diff --git a/.gitignore b/.gitignore index 539fedd..8a2cb3e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,2 @@ /.svn CMakeLists.txt.user* -/project_fs_build -/qad/qad_version.h -/qglengine/core/qglengine_version.h diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index bd49571..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "pip"] - path = pip - url = https://git.shs.tools/SHS/pip.git diff --git a/CMakeLists.txt b/CMakeLists.txt index b8390db..fa769fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,29 +1,12 @@ cmake_minimum_required(VERSION 3.0) -cmake_policy(SET CMP0011 NEW) # don`t affect includer policies cmake_policy(SET CMP0017 NEW) # need include() with .cmake -cmake_policy(SET CMP0020 NEW) # Automatically link Qt executables to qtmain target on Windows -if (POLICY CMP0053) - cmake_policy(SET CMP0053 NEW) # simpler variable expansion and escape sequence evaluation rules -endif() -project(libs) -set(PIP_CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/pip/cmake") -set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" "${PIP_CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/qad/cmake") -set(LIBPROJECT 1) -set(_qt_libs ) -set(_qt_apps ) -set(_qt_plugs) -include(GenerateExportHeader) -include(SDKMacros) -include(QADMacros) -include(DeployMacros) +project(qad) -if(NOT DEFINED BUILD_NUMBER) - set(BUILD_NUMBER 9999) +find_package(MinGW REQUIRED) +if (NOT DEFINED ANDROID_PLATFORM) + find_package(OpenGL REQUIRED) endif() -if("x${BUILD_NUMBER}" STREQUAL "x") - set(BUILD_NUMBER 0) -endif() - +include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) if(STATIC_LIB) set(QAD_LIB_TYPE STATIC) @@ -52,249 +35,29 @@ set_deploy_property(QAD ${QAD_LIB_TYPE} FULLNAME "${_QAD_DOMAIN}.*" COMPANY "${_QAD_COMPANY}") - -if(STATIC_LIB) - set(PIQt_LIB_TYPE STATIC) - add_definitions(-DPIQt_STATIC_DEFINE) - set(PIQt_LIB_TYPE_MSG "Static") -else() - set(PIQt_LIB_TYPE SHARED) - set(PIQt_LIB_TYPE_MSG "Shared") +# Version +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/qad_version.h") + file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/qad_version.h") endif() +#message(STATUS "Building QAD version ${QAD_VERSION} (${QAD_LIB_TYPE})") -set(_PIQt_MAJOR 1) -set(_PIQt_MINOR 0) -set(_PIQt_REVISION 0) -set(_PIQt_SUFFIX ) -set(_PIQt_COMPANY SHS) -set(_PIQt_DOMAIN org.SHS) -if(NOT DEFINED BUILD_NUMBER) - set(BUILD_NUMBER 9999) -endif() -set(PIQt_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/piqt/piqt_version.h") -set_version(PIQt - MAJOR "${_PIQt_MAJOR}" - MINOR "${_PIQt_MINOR}" - REVISION "${_PIQt_REVISION}" - BUILD "${BUILD_NUMBER}" - SUFFIX "${_PIQt_SUFFIX}" - OUTPUT "${PIQt_VERSION_FILE}") -set_deploy_property(PIQt ${_PIQt_LIB_TYPE} - FULLNAME "${_PIQt_DOMAIN}.*" - COMPANY "${_PIQt_COMPANY}") +file(GLOB CMAKES "cmake/*.cmake" "cmake/*.in") - -include_directories(${CMAKE_CURRENT_BINARY_DIR}/pip) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/qad) -include_directories(${CMAKE_CURRENT_BINARY_DIR}/piqt) -if(MINGW) - find_package(MinGW REQUIRED) -else() - if(APPLE) - set(CMAKE_INSTALL_RPATH "@executable_path/../Frameworks;@executable_path/lib;@loader_path/../lib") - set(CMAKE_MACOSX_RPATH TRUE) - if(CMAKE_CROSSCOMPILING) - set(CMAKE_INSTALL_NAME_DIR "@rpath") - else() - include_directories(/usr/local/include) - link_directories(/usr/local/lib) - endif() - else() - set(CMAKE_INSTALL_RPATH "\$ORIGIN;\$ORIGIN/lib") - endif() -endif() -if (DEFINED ANDROID_PLATFORM) - include_directories(${ANDROID_SYSTEM_LIBRARY_PATH}/usr/include) - #set(TARGET_INSTALL_PATH "${ANDROID_SYSTEM_LIBRARY_PATH}/usr/") - #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${ANDROID_NDK}/sysroot/usr/include") - #message("${ANDROID_SYSTEM_LIBRARY_PATH}/usr/include") - #message("${ANDROID_NDK}/sysroot/usr/include") -endif() -set(INSTALL_PREFIX "") -set(_plugins_default_ ON) -if(CMAKE_CROSSCOMPILING) - if (DEFINED ANDROID_PLATFORM) - set(_plugins_default_ OFF) - set(INSTALL_PREFIX "${CMAKE_FIND_ROOT_PATH}/") - else() - set(INSTALL_PREFIX "${CMAKE_STAGING_PREFIX}") - endif() -endif() -option(CROSSTOOLS "Crosstools minimal build" OFF) -option(LIB "System install" ON) -option(QGLVIEW "Build QGLview library and utils" OFF) -option(QGLENGINE "Build QGLENGINE library and utils" OFF) -option(UTILS "Build various utils" ${_plugins_default_}) -option(DESIGNER_PLUGINS "Build qt designer plugins" ${_plugins_default_}) -option(STATIC_LIB OFF) -if (CROSSTOOLS) - set(LIB 1) - set(QGLVIEW 0) - set(QGLENGINE 0) - set(UTILS 0) - set(DESIGNER_PLUGINS 0) -endif() -if (CMAKE_BUILD_TYPE MATCHES Debug) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -Wall") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3 -Wall") -else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wall") -endif() -set(CMAKE_CXX_STANDARD 11) - -set(PIP_LIBRARY pip) -set(PIP_INCLUDES) - -if(LIB) - if(WIN32) - if(MINGW) - set(CMAKE_INSTALL_PREFIX ${MINGW_DIR}) - endif() - else() - if (DEFINED ANDROID_PLATFORM) - set(CMAKE_INSTALL_PREFIX ${ANDROID_SYSTEM_LIBRARY_PATH}/usr) - else() - if(CMAKE_CROSSCOMPILING) - set(CMAKE_INSTALL_PREFIX ${CMAKE_STAGING_PREFIX}) - else() - set(CMAKE_INSTALL_PREFIX ${INSTALL_PREFIX}/usr/local) - endif() - endif() - endif() - message(STATUS "Install ${PROJECT_NAME} to system \"${CMAKE_INSTALL_PREFIX}\"") -else() - message(STATUS "Install ${PROJECT_NAME} to local \"bin\", \"lib\" and \"include\"") -endif() - -#message(${PIP_INCLUDES}) -if(CMAKE_CROSSCOMPILING OR (DEFINED ANDROID_PLATFORM)) - set(PIP_CMG "pip_cmg") - set(PIP_RC "pip_rc") - set(PIP_DEPLOY_TOOL "deploy_tool") -else() - set(PIP_CMG "${CMAKE_CURRENT_BINARY_DIR}/pip/utils/code_model_generator/pip_cmg") - set(PIP_RC "${CMAKE_CURRENT_BINARY_DIR}/pip/utils/resources_compiler/pip_rc") - set(PIP_DEPLOY_TOOL "${CMAKE_CURRENT_BINARY_DIR}/pip/utils/deploy_tool/deploy_tool") -endif() -if(WIN32) - set(PIP_DLL_DIR "${CMAKE_CURRENT_BINARY_DIR}/pip") -endif() - -set(QAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/qad) -set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) - -if (CROSSTOOLS) - - add_subdirectory(pip) - file(GLOB CMAKES "qad/cmake/*.cmake" "qad/cmake/*.in") +if (LIB) install(FILES ${CMAKES} DESTINATION ${CMAKE_ROOT}/Modules) - -else() - - include(QtWraps) - find_qt(Core QUIET) - set(QtVersions) - set(SomeQtFound 0) - foreach(_v ${_QT_VERSIONS_}) - option(Qt${_v} "Build for Qt${_v}" 1) - if (Qt${_v}) - #message("Qt${_v} -> ${LOCAL_FOUND${_v}}") - if (LOCAL_FOUND${_v}) - list(APPEND QtVersions Qt${_v}) - set(SomeQtFound 1) - endif() - endif() - endforeach() - - #if(UTILS) - # message(STATUS "Building with utils") - #else() - # message(STATUS "Building only libraries") - #endif() - - add_subdirectory(pip) - foreach(F ${PIP_MAIN_FOLDERS}) - list(APPEND PIP_INCLUDES "${F}") - endforeach(F) - add_subdirectory(cd_utils) - include_directories("${CMAKE_CURRENT_SOURCE_DIR}/cd_utils" "${CMAKE_CURRENT_BINARY_DIR}/cd_utils") - set(_DIRS) - if (SomeQtFound) - #message(STATUS "Building Qt-derived targets for ${QtVersions}") - add_subdirectory(qad) - include_directories(${qad_includes}) - add_subdirectory(piqt) - include_directories(${piqt_includes}) - set(_DIRS) - if (Qt5) - if (QGLVIEW) - list(APPEND _DIRS qglview) - endif() - if (QGLENGINE) - list(APPEND _DIRS qglengine) - endif() - endif() - foreach(_D ${_DIRS}) - list(APPEND QT_MULTILIB_LIST ${_D}) - add_subdirectory(${_D}) - endforeach(_D) - - macro(align_list _list _out) - set(_max_len 0) - foreach(_m ${_list}) - string(LENGTH "${_m}" _clen) - if (_clen GREATER _max_len) - set(_max_len ${_clen}) - endif() - endforeach() - set(${_out}) - foreach(_m ${_list}) - set(_am "${_m}") - while(TRUE) - string(LENGTH "${_am}" _clen) - if (_clen GREATER_EQUAL ${_max_len}) - break() - endif() - string(APPEND _am " ") - endwhile() - list(APPEND ${_out} "${_am}") - endforeach() - endmacro() - - macro(print_list _list _name) - if (NOT "x${_list}" STREQUAL "x") - message("") - message(" ${_name}:") - #align_list("${_list}" _alist) - foreach(_m ${_list}) - message(" * ${_m}") - endforeach() - endif() - endmacro() - - message("----------QAD-----------") - message(" Build for ${QtVersions}") - message(" QAD Version: ${QAD_VERSION}") - message(" QAD Linkage: ${QAD_LIB_TYPE_MSG}") - message(" PIQt Version: ${PIQt_VERSION}") - message(" PIQt Linkage: ${PIQt_LIB_TYPE_MSG}") - print_list("${_qt_libs}" "Libraries") - print_list("${_qt_apps}" "Applications") - print_list("${_qt_plugs}" "Plugins") - message("-----------------------") - message("") - + if (WIN32) + install(FILES ${QAD_VERSION_FILE} DESTINATION ${MINGW_INCLUDE}/qad) else() - message(STATUS "None of Qt found, skip Qt-derived targets") + install(FILES ${QAD_VERSION_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/qad) endif() - +else() + install(FILES ${QAD_VERSION_FILE} DESTINATION include/qad) endif() -if(WIN32) - foreach(PIP_LT ${PIP_MODULES}) - if (SomeQtFound) - qt_install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pip/lib${PIP_LT}.dll" DESTINATION QtBin) - endif() - endforeach() +add_subdirectory(libs) +if (UTILS) + add_subdirectory(utils) endif() + +copy_to_parent(qad_includes) + diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index aa1dfb8..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,62 +0,0 @@ -def build_docker(name) { - def image = "${name}-libs" - echo "Build image ${image}" - def pref = "" - if (env.DOCKER_PREFIX) { - pref = "--build-arg DOCKER_PREFIX=${env.DOCKER_PREFIX}/" - } - def jobs = 4 - if (env.JOBS_COUNT) { - jobs = "${env.JOBS_COUNT}" - } - def args = "${pref} --build-arg LIBS_BUILD_NUMBER=${env.BUILD_NUMBER} --build-arg JOBS_COUNT=${jobs}" - dir ("docker/${image}") { - sh "docker build ${args} --no-cache -t ${image} ." - } - return "\n - ${image}" -} -node { - stage("checkout") { - checkout scm - } - def _envmap = [:] - def _env = sh(script: "env", returnStdout: true).trim().split("\n") - _env.each{ l -> - def _ind = l.indexOf('='); - def _n = l.substring(0, _ind); - def _v = l.substring(_ind + 1); - _envmap["${_n}"] = "${_v}"; - } - def _msg = "Built images:" - def platforms = ['debian', 'osx', 'windows', 'android', 'pi'] - for (int i = 0; i < platforms.size(); ++i) { - if (_envmap["BUILD_${platforms[i]}"] == "1") { - stage("${platforms[i]}-libs") { - _msg += build_docker("${platforms[i]}") - } - } - } - sh "docker system prune -f" - echo "${_msg}" -} -pipeline { - agent { - label 'master' - } - stages { - stage("PIP doc") { - steps { - checkout scm - sh "rm -rf share" - sh "rm -vf *.zip" - sh "mkdir -p build" - sh "cd build && cmake -DLIB=0 -DCMAKE_INSTALL_PREFIX=`pwd` ../" - sh "cd build && make doc" - sh "cd share/doc && zip -r ../../pip_doc.zip pip" - sh "cp share/doc/pip/html/pip.qch ./" - archiveArtifacts 'pip_doc.zip' - archiveArtifacts 'pip.qch' - } - } - } -} diff --git a/README.md b/README.md index 9ac5e18..5c60939 100644 --- a/README.md +++ b/README.md @@ -1,54 +1,10 @@ -# Main SHS SDK libraries repo +# Qt for ADvanced ## Introduction -This repo contains PIP, QAD and derived projects: -* cd_utils - PIP-based client/server library for read, transmit and use custom structures of coefficients +This repo contains QAD and PIQt projects: + * qcd_utils - Qt bindings to CDUtils and "CD Pult" executable - full-featured CD client * piqt - helpers to convert PIP <-> Qt types * piqt_utils - Gui libraries and executables to edit PIConnection configs and watch PIIntrospection * qglview - old Qt-base OpenGL engine -* qglengine - new Qt-base OpenGL engine - -## Compile -This repo can be compile with GCC/MinGW/Clang, for Qt 4/5. - -If there is no Qt found, builds only PIP and cd_utils. - -CMake options: -* **LIB** - if 1 then install to system directories: MinGW on Windows, /usr/local on Linux/MacOS, ${ANDROID_SYSTEM_LIBRARY_PATH} on Android. If 0 then install to ${CMAKE_INSTALL_PREFIX}. Enabled by default -* **UTILS** - build or not executable utilites, enabled by default -* **DESIGNER_PLUGINS** - build or not Qt Designer plugins, enabled by default -* **QGLVIEW** - build or not QGLView, disabled by default -* **QGLENGINE** - build or not QGLEngine, disabled by default - -## Windows scripts -Build steps for i686 architecture: -1. unzip mingw.7z to C:\mingw -2. unzip qt.7z to C:\qt -3. download and install cmake from https://cmake.org/download/ -4. Prepare environment - - set prefix for mingw e.g.: for C:\mingw\7_1_x32\ - set SDK_MINGW_DIR=C:\mingw\7_1_x - - set prefix for Qt5 e.g.: for C:\qt\qt5120_win32\ - set SDK_QT5_DIR=C:\qt\qt5120_win - - set SDK_CMAKE_DIR=C:\cmake -5. run make_libs32.bat - -Build steps for amd64 architecture: - -- follow previos steps, but replace '32' to '64' - -Build steps for both architectures: - -- follow previos steps, but on '4' state run make_libs_all.bat - -## Non-Windows scripts -Script "make_libs.sh" compile and install SDK for current environment, e.g. -`./make_libs.sh -j4` - -## Docker -This repo provide Dockerfile, so you can exec `docker build -t libs .` in this directory -and make docker image "libs" with installed SHS SDK for: -* Debian 10 -* Windows x64 -* MacOS -* Android ndk 21 armeabi-v71, arm64-v8a, x86, x86_64 diff --git a/SDKMacros.cmake b/SDKMacros.cmake deleted file mode 100644 index de07b6a..0000000 --- a/SDKMacros.cmake +++ /dev/null @@ -1,107 +0,0 @@ - -macro(sdk_install _DIR IS_APP _TARGET _H_FILES _QM_FILES) - #message("QM=${_QM_FILES}") - if((NOT ${IS_APP}) AND (NOT "${_H_FILES}" STREQUAL "")) - if(LIB) - if(WIN32) - install(FILES ${_H_FILES} DESTINATION ${MINGW_INCLUDE}/${_DIR}) - else() - install(FILES ${_H_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${_DIR}) - endif() - else() - install(FILES ${_H_FILES} DESTINATION include/${_DIR}) - endif() - endif() - if (NOT "${_TARGET}" STREQUAL "") - if(LIB) - if(WIN32) - if (${IS_APP}) - qt_install(TARGETS ${_TARGET} DESTINATION ${MINGW_BIN}) - qt_install(TARGETS ${_TARGET} DESTINATION QtBin) - else() - qt_install(TARGETS ${_TARGET} ARCHIVE DESTINATION ${MINGW_LIB}) - qt_install(TARGETS ${_TARGET} RUNTIME DESTINATION ${MINGW_BIN}) - qt_install(TARGETS ${_TARGET} RUNTIME DESTINATION QtBin) - endif() - else() - if (${IS_APP}) - qt_install(TARGETS ${_TARGET} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) - else() - qt_install(TARGETS ${_TARGET} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) - endif() - endif() - if(NOT "x${_QM_FILES}" STREQUAL "x") - qt_install(LANG ${_QM_FILES} DESTINATION QtLang) - endif() - else() - if(${IS_APP}) - qt_install(TARGETS ${_TARGET} DESTINATION bin) - else() - if(WIN32) - qt_install(TARGETS ${_TARGET} RUNTIME DESTINATION bin) - qt_install(TARGETS ${_TARGET} ARCHIVE DESTINATION lib) - else() - qt_install(TARGETS ${_TARGET} DESTINATION lib) - endif() - endif() - if(NOT "x${_QM_FILES}" STREQUAL "x") - qt_install(LANG ${_QM_FILES} DESTINATION lang) - endif() - endif() - endif() -endmacro() - - -macro(copy_to_parent _inc_var) - set(QT_MULTILIB_LIST ${QT_MULTILIB_LIST} PARENT_SCOPE) - set(_qt_libs ${_qt_libs} PARENT_SCOPE) - set(_qt_apps ${_qt_apps} PARENT_SCOPE) - set(_qt_plugs ${_qt_plugs} PARENT_SCOPE) - if (NOT "x${_inc_var}" STREQUAL "x") - set(${_inc_var} ${${_inc_var}} PARENT_SCOPE) - endif() - if (LIB) - set(_ALL_TARGETS ${_ALL_TARGETS} PARENT_SCOPE) - endif() -endmacro() - - -macro(add_directories_with_include multilib_prefix) - set(DIRS) - file(GLOB _dl "[^.]*") - foreach(_d ${_dl}) - if(IS_DIRECTORY ${_d}) - list(APPEND DIRS ${_d}) - endif() - endforeach() - - set(inc_var ${multilib_prefix}includes) - set(${inc_var}) - foreach(_d ${DIRS}) - get_filename_component(_dname "${_d}" NAME) - list(APPEND QT_MULTILIB_LIST ${multilib_prefix}${_dname}) - list(APPEND ${inc_var} "${_d}") - list(APPEND ${inc_var} "${CMAKE_CURRENT_BINARY_DIR}/${_dname}") - endforeach() - - include_directories(${${inc_var}}) - foreach(_d ${DIRS}) - add_subdirectory(${_d}) - endforeach() - - copy_to_parent(${inc_var}) -endmacro() - - -macro(add_directories multilib_prefix) - include_directories(${${multilib_prefix}includes}) - file(GLOB _dl "[^.]*") - foreach(_d ${_dl}) - if(IS_DIRECTORY ${_d}) - add_subdirectory(${_d}) - endif() - endforeach() - - copy_to_parent(${multilib_prefix}includes) -endmacro() - diff --git a/cd_utils/CMakeLists.txt b/cd_utils/CMakeLists.txt deleted file mode 100644 index f1c6a5d..0000000 --- a/cd_utils/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -project(cd_utils) -find_package(MinGW REQUIRED) -include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${PIP_INCLUDES}) -file(GLOB CPPS_UTILS "cdutils_*.cpp") -file(GLOB HDRS_UTILS "cdutils_*.h") -add_library(${PROJECT_NAME} SHARED ${CPPS_UTILS} ${HDRS_UTILS}) -target_link_libraries(${PROJECT_NAME} ${PIP_LIBRARY}) -generate_export_header(${PROJECT_NAME}) -list(APPEND HDRS_UTILS "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_export.h") - -add_executable(cdutilstest "cdutilstest.cpp" "cdtest.h") -target_link_libraries(cdutilstest ${PIP_LIBRARY} ${PROJECT_NAME}) -message(STATUS "Building ${PROJECT_NAME}") - -if(LIB) - list(APPEND _ALL_TARGETS ${PROJECT_NAME}) - set(_ALL_TARGETS ${_ALL_TARGETS} PARENT_SCOPE) - if(WIN32) - install(FILES ${HDRS_UTILS} DESTINATION ${MINGW_INCLUDE}) - install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${MINGW_LIB}) - install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${MINGW_BIN}) - else() - install(FILES ${HDRS_UTILS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include) - install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) - endif() - #message(STATUS "Install ${PROJECT_NAME} to system \"${CMAKE_INSTALL_PREFIX}\"") -else() - if(WIN32) - install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) - install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION lib) - else() - install(TARGETS ${PROJECT_NAME} DESTINATION lib) - endif() - install(FILES ${HDRS_UTILS} DESTINATION include) - #message(STATUS "Install ${PROJECT_NAME} to local \"bin\"") -endif() diff --git a/cd_utils/cdtest.h b/cd_utils/cdtest.h deleted file mode 100644 index c2e45d6..0000000 --- a/cd_utils/cdtest.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CDTEST_H -#define CDTEST_H - - -enum KDescription { - First, //f Первый - Second, //b Второй -}; - -#endif // CDTEST_H diff --git a/cd_utils/cdutils_c.cpp b/cd_utils/cdutils_c.cpp deleted file mode 100644 index 30a5fae..0000000 --- a/cd_utils/cdutils_c.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "cdutils_c.h" -#include "cdutils_core.h" - -using namespace CDUtils; - -CInterface C; - - -CInterface::CInterface(): Interface(CDType::cdC) { -} - - -void CInterface::sendCommand(const CDType & c) { - core->sendCommand(c); -} - - -void CInterface::connect(const CDType & c, PIObject * o, Handler eh) { - core->registerCHandler(c, o, eh); -} - - -void CInterface::autoConnect(PIObject * o, const PIString & prefix) { - if (!o) return; - uint cid = o->classNameID(); - if (!PIObject::__meta_data().contains(cid)) return; - PIMap eh_map; - PIObject::__MetaData & md(PIObject::__meta_data()[cid]); - PIMap::const_iterator it; - for (it = md.eh_func.constBegin(); it != md.eh_func.constEnd(); ++it) { - eh_map[it.value().func_name] = (Handler)it.value().addr; - //piCout << "func" << it.value().func_name; - } - PIVector cl = C.root().children(); - piForeachC (CDType * c, cl) { - PIString cp = prefix + c->pathString().join("_"); - if (cp.isEmpty()) continue; - if (!eh_map.contains(cp)) continue; - connect(*c, o, eh_map[cp]); - } -} diff --git a/cd_utils/cdutils_c.h b/cd_utils/cdutils_c.h deleted file mode 100644 index a517e8c..0000000 --- a/cd_utils/cdutils_c.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - CD Utils - Control-Debug utilites - - Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef CDUTILS_C_H -#define CDUTILS_C_H - -#include "cdutils_interface.h" -#include "cd_utils_export.h" - - -namespace CDUtils { - - -class CD_UTILS_EXPORT CInterface: public Interface -{ - PIOBJECT_SUBCLASS(CInterface, Interface) -public: - CInterface(); - - void sendCommand(const CDType & c); - void connect(const CDType & c, PIObject * o, Handler eh); - void autoConnect(PIObject * o, const PIString & prefix = PIStringAscii("c_")); - -}; - -} - -extern CD_UTILS_EXPORT CDUtils::CInterface C; - -#endif // CDUTILS_C_H diff --git a/cd_utils/cdutils_core.cpp b/cd_utils/cdutils_core.cpp deleted file mode 100644 index c03c327..0000000 --- a/cd_utils/cdutils_core.cpp +++ /dev/null @@ -1,606 +0,0 @@ -#include "cdutils_core.h" -#include "cdutils_parser.h" -#include "piconfig.h" -#include "piiobytearray.h" -#include "piiostring.h" -#include "pifile.h" - -using namespace CDUtils; - -const char CDCore::app_config[] = - "include = cd_ip.conf\n\ - port_rec = 2\n\ - port_send = 1\n\ - [connection]\n\ - device.cd = peer://cd_app:cd_pult #s\n\ - []\n\ - connectionmodel = AAAM2Xja7VXLTttAFD12QpsikKjUSixYlLbKEpIUtVIlVEfqhk2FWuiGRRolUYtoHgrmpYiv6IItf8AveMMH9E/YsG6Ph3sde5hGoQoblLGuPHfunTPjc49nADxDA110+LTYC7FrPCAPeAO+vZu+aX7c/8PGd45WCJC0OGcfT6FDnmfSTPtwhZFt3HjgDs/Qtu5jPbZHtI/x50XfIzMQbdwEolbg9INP4ku++myPaUtCHYRaT2j1ldIh3VP60/Qff8vSfXLu9BP6JX9K/0TVH6jqVe22P1X/fao/oddWu/paDs1vBf9Jv/EZ91clbyHqv7BL6sscDOd4v4WTqs6jzaHGJ8QJerxlpJSpdZ7IWFJvDW7I2JxZqIM62k6A57RZmMQGmlyrxdV+WGBnmR01mXPI267hBKwp4FeBeo9VPtssxyb7rzHg1B7T9nCMU45U8BZlWuVWtIcD/CRGOqtsbW09851tXsHN0UTlLIAdASjSXnLyLn+H7L2+xbGYvC63Ezqg543egkLmn8qnRF6USbM4Qp9godkhzI777Ne5bCIt/5UtGz2o/yGby0nKpjqmbOa1ynkjmyzIrzvIZUeBPjvlUmbh32EFJbGyJZhR8YcvlS+3TpjhqeWSyvUkpbI9plSWtcKLcsK05beOJVEnhaEFfHEH+RwpeMcpn1JKGqWMNOL+G6wZyahlpdVOtufKfbDS+guLke9O\n\ - "; - -const char CDCore::pult_config[] = - "include = cd_ip.conf\n\ - port_rec = 1\n\ - port_send = 2\n\ - [connection]\n\ - device.cd = peer://cd_pult:cd_app #s\n\ - []\n\ - connectionmodel = AAAM2Xja7VXLTttAFD12QpsikKjUSixYlLbKEpIUtVIlVEfqhk2FWuiGRRolUYtoHgrmpYiv6IItf8AveMMH9E/YsG6Ph3sde5hGoQoblLGuPHfunTPjc49nADxDA110+LTYC7FrPCAPeAO+vZu+aX7c/8PGd45WCJC0OGcfT6FDnmfSTPtwhZFt3HjgDs/Qtu5jPbZHtI/x50XfIzMQbdwEolbg9INP4ku++myPaUtCHYRaT2j1ldIh3VP60/Qff8vSfXLu9BP6JX9K/0TVH6jqVe22P1X/fao/oddWu/paDs1vBf9Jv/EZ91clbyHqv7BL6sscDOd4v4WTqs6jzaHGJ8QJerxlpJSpdZ7IWFJvDW7I2JxZqIM62k6A57RZmMQGmlyrxdV+WGBnmR01mXPI267hBKwp4FeBeo9VPtssxyb7rzHg1B7T9nCMU45U8BZlWuVWtIcD/CRGOqtsbW09851tXsHN0UTlLIAdASjSXnLyLn+H7L2+xbGYvC63Ezqg543egkLmn8qnRF6USbM4Qp9godkhzI777Ne5bCIt/5UtGz2o/yGby0nKpjqmbOa1ynkjmyzIrzvIZUeBPjvlUmbh32EFJbGyJZhR8YcvlS+3TpjhqeWSyvUkpbI9plSWtcKLcsK05beOJVEnhaEFfHEH+RwpeMcpn1JKGqWMNOL+G6wZyahlpdVOtufKfbDS+guLke9O\n\ - "; - - -int __Core_Initializer__::count_(0); -CDCore * __Core_Initializer__::__instance__(0); -const uchar header_direct = 0x80; -const uchar header_transfer = 0x81; - - -__Core_Initializer__::__Core_Initializer__() { - count_++; - if (count_ > 1) return; - __instance__ = new CDCore(); -} - - -__Core_Initializer__::~__Core_Initializer__() { - count_--; - if (count_ < 0) { - count_ = 0; - return; - } - if (count_ > 0) return; - if (__instance__) { - delete __instance__; - __instance__ = 0; - } -} - - - - -CDCore::CDCore() { - setName("CDCore"); - x_timer.setName("__S__.CDCore.x_timer"); - datatr.setPacketSize(960); - CONNECTU(&connection, dataReceivedEvent, this, dataReceived); - CONNECTU(PICout::Notifier::object(), finished, this, piCoutFinished); - /*PIString s(app_config); - connection.configureFromString(&s); - connection.start();*/ - need_rebuild_x = x_pult_side = false; - k_.cd_type_ = CDType::cdK; - x_.cd_type_ = CDType::cdX; - c_.cd_type_ = CDType::cdC; - m_.cd_type_ = CDType::cdM; - initRoot(&k_); - initRoot(&x_); - initRoot(&c_); - initRoot(&m_); - - CONNECTU(&sendt, started, this, sendThread) - CONNECTU(&datatr, sendRequest, this, dtSendRequest) - CONNECTU(&datatr, receiveFinished, this, dtReceiveFinished) - CONNECTU(&x_timer, tickEvent, this, xTimerTick) - - /*k_[1] = KType(1, "123", "120+3", "comment"); - k_[2] = KType(2, "1", "2", "comm"); - k_[4] = KType(4, "-0.6", "-6/10", "mment"); - k_.section(10)[5] = KType(5, "8", "2*2*2", "88"); - k_.section(10).section(50)[100] = KType(100, "8", "2*2*2", "88"); - k_.section(11)[3] = KType(3, "1", "1", "88"); - k_.section(11)[4] = KType(4, "0", "0", "88"); - k_.section(11)[6] = KType(6, "0", "0", "88");*/ - //piCout << s; -} - - -CDCore::~CDCore() { - x_timer.stop(true); - datatr.stop(); - sendt.stop(); - sendt.waitForFinish(10); - connection.stop(); -} - - -void CDCore::cd_write(CDSection * cd, PIIODevice * d) { - cd->write(d, PIString()); -} - - -void CDCore::cd_read(CDSection * cd, PIIODevice * d) { - PIConfig conf(d, PIIODevice::ReadOnly); - cd->read(&(conf.rootEntry())); - if (cd->cd_type_ == CDType::cdX) - x_selected = cd->collectX(); - initRoot(cd); - raiseChangedGlobal(cd->cd_type_); - /*PIVector ds = connection.allDevices(); - piForeach(PIIODevice * d, ds) { - if (d) - piCoutObj << d->constructFullPath() << d->isOpened(); - }*/ -} - - -void CDCore::cd_parse(CDSection * cd, PIIODevice * d) { - *cd = CDParser::parse(d, cd->cd_type_); - initRoot(cd); - raiseChangedGlobal(cd->cd_type_); -} - - -void CDCore::cd_update(CDSection * cd, PIIODevice * d, UpdateModeFlags mode) { - CDSection ucd = *cd; - cd_parse(cd, d); - /*bool kn = true; - if (!ucd.isEmpty()) - if (!ucd.isSameStructure(k_)) { - piCout << "ask for save names"; - K_KeepNamesRequest(&kn); - }*/ - ucd.update(*cd, mode); - //piCout << k_.count() << ucd.count(); - *cd = ucd; - initRoot(cd); - raiseChangedGlobal(cd->cd_type_); -} - - -void CDCore::cd_calculate(CDSection * cd) { - cd->calculate(); - raiseChangedGlobal(cd->cd_type_); -} - - -void CDCore::cd_send(CDSection * cd, CDPacketType pt, bool direct) { - if (!cd) return; - PIByteArray ba, sba; - PIIOByteArray iob(&ba, PIIODevice::ReadWrite); - cd_write(cd, &iob); - //piCoutObj << PIString(ba); - sba = makeHeader(pt, 0); - sba << ba; - if (direct) - sendDirect(sba); - else - sendThreaded(sba); -} - - -void CDCore::send(CDType::cdT cdt) { - CDPacketType pt = CD_Ping; - switch (cdt) { - case CDType::cdK: pt = CD_KSend; break; - case CDType::cdX: pt = CD_XSend; break; - case CDType::cdC: pt = CD_CSend; break; - case CDType::cdM: pt = CD_MSend; break; - default: break; - } - piCoutObj << "send" << typeLetter(cdt); - cd_send(root(cdt), pt); -} - - -void CDCore::request(CDType::cdT cdt) { - CDPacketType pt = CD_Ping; - switch (cdt) { - case CDType::cdK: pt = CD_KQuery; break; - case CDType::cdX: pt = CD_XQuery; break; - case CDType::cdC: pt = CD_CQuery; break; - case CDType::cdM: pt = CD_MQuery; break; - default: break; - } - piCoutObj << "request" << typeLetter(cdt); - PIByteArray sba = makeHeader(pt, 0); - sendThreaded(sba); -} - - -void CDCore::initApp() { - init(appConfig(), false); -} - - -void CDCore::initPult() { - init(pultConfig(), true); -} - - -void CDCore::init(const PIString & configuration, bool pult) { - PIString c = configuration; - //piCoutObj << "init" << c; - connection.stop(); - connection.removeAllDevices(); - connection.configureFromString(&c); - connection.start(); - x_pult_side = pult; -} - - -void CDCore::stop() { - x_timer.stop(); - x_timer.waitForFinish(1000); - connection.stop(); -} - - -void CDCore::release() { - stop(); - connection.removeAllDevices(); -} - - -void CDCore::startX(double freq) { - //piCout << "start x" << x_timer.isRunning() << freq; - if (!x_timer.isRunning()) - x_timer.start(1000. / piMaxd(freq, 0.01)); -} - - -void CDCore::stopX() { - x_timer.stop(); - x_timer.waitForFinish(1000); -} - - -void CDCore::sendCommand(const CDType & c) { - //piCoutObj << "C_sendCommand" << c; - PIByteArray sba = makeHeader(CD_Command, 0); - sba << c.path(); - sendDirect(sba); -} - - -void CDCore::registerCHandler(const CDType & c, PIObject * o, Handler h) { - PIString sp = pathToString(c.path()); - if (sp.isEmpty() || !h) return; - //piCout << "register" << sp; - c_handlers[sp] = OHPair(o, h); -} - - -void CDCore::sendMessage(const CDType & m, MessageType mt, const PIString & msg) { - if (msg.isEmpty() || (m.cd_type() != CDType::cdM)) return; - PIByteArray sba = makeHeader(CD_Message, 0); - sba << m.path() << int(mt) << msg; - sendDirect(sba); -} - - -CDSection * CDCore::root(CDType::cdT cdt) { - switch (cdt) { - case CDType::cdK: return &k_; break; - case CDType::cdX: return &x_; break; - case CDType::cdC: return &c_; break; - case CDType::cdM: return &m_; break; - default: break; - } - return 0; -} - - -PIString CDCore::typeLetter(CDType::cdT cdt) { - switch (cdt) { - case CDType::cdK: return PIStringAscii("k"); break; - case CDType::cdX: return PIStringAscii("x"); break; - case CDType::cdC: return PIStringAscii("c"); break; - case CDType::cdM: return PIStringAscii("m"); break; - default: break; - } - return PIString(); -} - - -CDCore * CDCore::instance() { - /*static CDCore * ret = new CDCore(); - return ret;*/ - return __Core_Initializer__::__instance__; -} - - -bool CDCore::destroy() { - if (!__Core_Initializer__::__instance__) return false; -// piCout << "delete Core ..."; - delete __Core_Initializer__::__instance__; -// piCout << "delete Core ok"; - __Core_Initializer__::__instance__ = 0; - __Core_Initializer__::count_ = 0; - return true; -} - - -void CDUtils::CDCore::K_DirectChange(PIDeque path, PIString value) { -// piCoutObj << "K_DirectChange"; - PacketKDirectChange p; - p.path = path; - p.value = value; - PIByteArray sba = makeHeader(CD_KDirectChange, 0); - sba << p; - sendDirect(sba); -} - - -void CDCore::sendThread() { - if (send_data.size_s() < 4) return; - PacketHeader h; - memcpy(&h, send_data.data(), sizeof(h)); - bool ok = datatr.send(send_data); - switch (h.type) { - case CD_KSend: - if (ok) K_Sended(); - else K_SendFail(); - break; - case CD_KQuery: - if (!ok) K_ReceiveFail(); - break; - case CD_XSend: - if (ok) X_Sended(); - else X_SendFail(); - break; - case CD_XQuery: - if (!ok) X_ReceiveFail(); - break; - case CD_CSend: - if (ok) C_Sended(); - else C_SendFail(); - break; - case CD_CQuery: - if (!ok) C_ReceiveFail(); - break; - case CD_MSend: - if (ok) M_Sended(); - else M_SendFail(); - break; - case CD_MQuery: - if (!ok) M_ReceiveFail(); - break; - default: break; - } -} - - -void CDCore::xTimerTick() { - //piCout << "x tick" << x_pult_side; - PIByteArray ba; - x_mutex.lock(); - if (x_pult_side) { - ba = makeHeader(CD_XRequest, 0); - if (need_rebuild_x) { - x_selected = x_.collectX(); - //piCout << "collectX" << x_selected.size(); - need_rebuild_x = false; - } - ba << x_selected; - //piCout << "x pult send" << x_selected.size(); - } else { - ba = makeHeader(CD_XValues, 0); - ba << x_selected; - piForeachC (PIDeque & p, x_selected) { - x_[p].writeX(ba); - } - //piCout << "x app" << x_selected.size(); - } - x_mutex.unlock(); - sendDirect(ba); -} - - -void CDCore::piCoutFinished(int id, PIString * buffer) { - if (!buffer || !(id == 1)) return; - PIString sp = buffer->takeRange("[", "]"); - PIDeque p = CDCore::stringToPath(sp); - sendMessage(m_[p], Log, *buffer); - delete buffer; -} - - -void CDCore::initRoot(CDSection * r) { - r->name = "__root__"; - r->alias = "root"; - r->makePath(); - r->calculate(); -} - - -PIByteArray CDCore::makeHeader(CDPacketType type, int session_id) const { - PacketHeader h; - h.type = type; - h.session_id = session_id; - PIByteArray ret; ret << h; - return ret; -} - - -void CDCore::sendDirect(PIByteArray & ba) { - ba.push_front(header_direct); - connection.writeByName("cd", ba); -} - - -void CDCore::sendThreaded(PIByteArray & ba) { - if (sendt.isRunning()) { - piCoutObj << "Send in process, abort"; - return; - } - send_data = ba; - sendt.startOnce(); -} - - -void CDCore::procReceivedPacket(PIByteArray & ba) { - PacketHeader h; - ba >> h; - switch(h.type) { - case CD_Ping: - //piCoutObj << "ping"; - break; - case CD_KQuery: - send(CDType::cdK); - break; - case CD_KSend: { - PIByteArray k; - ba >> k; - k << uchar(0); - PIString s = PIString::fromUTF8((const char *)k.data()); - PIIOString ios(&s); - cd_read(&k_, &ios); - K_Received(); - piCoutObj << "K received"; - } break; - case CD_KDirectChange: { - PacketKDirectChange p; - ba >> p; - k_[p.path].setValue(p.value); - } break; - case CD_XQuery: - send(CDType::cdX); - break; - case CD_XSend: { - PIByteArray x; - ba >> x; - x << uchar(0); - PIString s = PIString::fromUTF8((const char *)x.data()); - PIIOString ios(&s); - cd_read(&x_, &ios); - x_selected = x_.collectX(); - X_Received(); - piCoutObj << "X received"; - } break; - case CD_XRequest: { - if (x_pult_side) break; - //break; - x_mutex.lock(); - x_selected.clear(); - ba >> x_selected; - //piCout << "X req" << x_selected.size(); - x_.setSelectedX(false); - piForeachC (PIDeque & p, x_selected) { - x_[p].x_enabled = true; - } - x_mutex.unlock(); - } break; - case CD_XValues: { - if (!x_pult_side) break; - PIVector > x_vals; - ba >> x_vals; - x_mutex.lock(); - piForeachC (PIDeque & p, x_vals) { - x_[p].readX(ba); - } - x_mutex.unlock(); - X_ReceivedX(x_vals); - } break; - case CD_CQuery: - send(CDType::cdC); - break; - case CD_CSend: { - piCoutObj << "C received"; - PIByteArray c; - ba >> c; - c << uchar(0); - PIString s = PIString::fromUTF8((const char *)c.data()); - PIIOString ios(&s); - cd_read(&c_, &ios); - C_Received(); - } break; - case CD_Command: { - piCoutObj << "C command"; - PIDeque p; - ba >> p; - if (p.isEmpty()) return; - PIString sp = pathToString(p); - OHPair h = c_handlers.value(sp, OHPair(0, 0)); - //piCoutObj << "found" << sp << h.first; - if (h.first && h.second) h.second(h.first); - } break; - case CD_MQuery: - send(CDType::cdM); - break; - case CD_MSend: { - piCoutObj << "M received"; - PIByteArray c; - ba >> c; - c << uchar(0); - PIString s = PIString::fromUTF8((const char *)c.data()); - PIIOString ios(&s); - cd_read(&m_, &ios); - M_Received(); - } break; - case CD_Message: { - PIDeque p; - ba >> p; - piCoutObj << "M message" << p; - if (p.isEmpty()) return; - int t = 0; - PIString msg; - ba >> t >> msg; - //piCoutObj << "found" << sp << h.first; - //piCoutObj << "M message invoke"; - M_Message(p, t, msg); - } break; - default: break; - } -} - - -void CDCore::raiseChangedGlobal(CDType::cdT cdt) { - switch (cdt) { - case CDType::cdK: K_ChangedGlobal(); break; - case CDType::cdX: X_ChangedGlobal(); break; - case CDType::cdC: C_ChangedGlobal(); break; - case CDType::cdM: M_ChangedGlobal(); break; - default: break; - } -} - - -PIString CDCore::pathToString(const PIDeque & p) { - PIString ret; - for (int i = 0; i < p.size_s(); ++i) { - if (!ret.isEmpty()) ret += "."; - ret << p[i]; - } - return ret; -} - - -PIDeque CDCore::stringToPath(const PIString & p) { - PIDeque ret; - PIStringList sl = p.split("."); - piForeachC (PIString & s, sl) - ret << s.toInt(); - return ret; -} - - -void CDUtils::CDCore::dataReceived(const PIString & from, const PIByteArray & data) { - //piCoutObj << "dataReceived" << from << data.size(); - PIIODevice * d = connection.deviceByName("cd"); - if (d && d == connection.deviceByFullPath(from)) { - if (data.size() >= sizeof(4)) { - PIByteArray ba = data; - uchar header = ba.take_front(); - if (header == header_transfer) { - datatr.received(ba); - } - if (header == header_direct) { - procReceivedPacket(ba); - } - } - } -} - - -void CDCore::dtSendRequest(PIByteArray & data) { - data.push_front(header_transfer); - connection.writeByName("cd", data); - //piCoutObj << "send" << data.size() << ret; -} - - -void CDCore::dtReceiveFinished(bool ok) { - if (!ok) return; - PIByteArray ba = datatr.data(); - procReceivedPacket(ba); -} - diff --git a/cd_utils/cdutils_core.h b/cd_utils/cdutils_core.h deleted file mode 100644 index a0d4e79..0000000 --- a/cd_utils/cdutils_core.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - CD Utils - Control-Debug utilites - - Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef CDUTILS_CORE_H -#define CDUTILS_CORE_H - -#include "cdutils_types.h" -#include "cdutils_protocol.h" -#include "piconnection.h" -#include "pidatatransfer.h" -#include "cd_utils_export.h" - - -namespace CDUtils { - -class CDCore; - - -class CD_UTILS_EXPORT __Core_Initializer__ { -public: - __Core_Initializer__(); - ~__Core_Initializer__(); - static int count_; - static CDCore * __instance__; -}; - - -class CD_UTILS_EXPORT CDCore: public PIObject -{ - PIOBJECT(CDUtils::CDCore) - friend class __Core_Initializer__; - friend class CDSection; - friend class Interface; - friend class XInterface; -public: - static CDCore * instance(); - static bool destroy(); - - EVENT(K_Sended) - EVENT(K_SendFail) - EVENT(K_Received) - EVENT(K_ReceiveFail) - EVENT(K_ChangedGlobal) - EVENT_HANDLER2(void, K_DirectChange, PIDeque, path, PIString, value); - - EVENT(X_Sended) - EVENT(X_SendFail) - EVENT(X_Received) - EVENT(X_ReceiveFail) - EVENT(X_ChangedGlobal) - EVENT1(X_ReceivedX, PIVector >, pathes) - - EVENT(C_Sended) - EVENT(C_SendFail) - EVENT(C_Received) - EVENT(C_ReceiveFail) - EVENT(C_ChangedGlobal) - - EVENT(M_Sended) - EVENT(M_SendFail) - EVENT(M_Received) - EVENT(M_ReceiveFail) - EVENT(M_ChangedGlobal) - EVENT3(M_Message, PIDeque, path, int, type, PIString, msg) - - void cd_write (CDSection * cd, PIIODevice * d); - void cd_read (CDSection * cd, PIIODevice * d); - void cd_parse (CDSection * cd, PIIODevice * d); - void cd_update (CDSection * cd, PIIODevice * d, UpdateModeFlags mode); - void cd_calculate(CDSection * cd); - void cd_send (CDSection * cd, CDPacketType pt, bool direct = false); - void send(CDType::cdT cdt); - void request(CDType::cdT cdt); - void initApp(); - void initPult(); - void init(const PIString & configuration, bool pult = false); - void stop(); - void release(); - void startX(double freq = 20.); - void stopX(); - void sendCommand(const CDType & c); - void registerCHandler(const CDType & c, PIObject * o, Handler h); - bool inProgress() {return sendt.isRunning();} - void sendMessage(const CDType & m, MessageType mt, const PIString & msg); - - CDSection * root(CDType::cdT cdt); - PIString typeLetter(CDType::cdT cdt); - static PIString pathToString(const PIDeque & p); - static PIDeque stringToPath(const PIString & p); - - static PIString pultConfig() {return PIString(pult_config);} - static PIString appConfig() {return PIString(app_config);} - -private: - CDCore(); - ~CDCore(); - EVENT_HANDLER2(void, dataReceived, const PIString &, from, const PIByteArray &, data); - EVENT_HANDLER1(void, dtSendRequest, PIByteArray &, data); - EVENT_HANDLER1(void, dtReceiveFinished, bool, ok); - EVENT_HANDLER(void, sendThread); - EVENT_HANDLER(void, xTimerTick); - EVENT_HANDLER2(void, piCoutFinished, int, id, PIString*, buffer); - void initRoot(CDSection * r); - PIByteArray makeHeader(CDPacketType type, int session_id = 0) const; - void sendDirect(PIByteArray & ba); - void sendThreaded(PIByteArray & ba); - void procReceivedPacket(PIByteArray & ba); - void raiseChangedGlobal(CDType::cdT cdt); - - typedef PIPair OHPair; - - static const char app_config[], pult_config[]; - PIConnection connection; - PIDataTransfer datatr; - PIByteArray send_data; - PIThread sendt; - PITimer x_timer; - CDSection k_, x_, c_, m_; - PIMutex x_mutex; - PIVector > x_selected; - PIMap c_handlers; - bool need_rebuild_x, x_pult_side; - -}; - - -static __Core_Initializer__ __Core_initializer__; - -} - -#endif // CDUTILS_CORE_H diff --git a/cd_utils/cdutils_interface.cpp b/cd_utils/cdutils_interface.cpp deleted file mode 100644 index a37d818..0000000 --- a/cd_utils/cdutils_interface.cpp +++ /dev/null @@ -1,217 +0,0 @@ -#include "cdutils_interface.h" -#include "cdutils_core.h" -#include "piconfig.h" -#include "pifile.h" - -using namespace CDUtils; - - -Interface::Interface(CDType::cdT type_) { - core = CDCore::instance(); - s = core->root(type_); - type = type_; - //piCoutObj << (void*)this << core; - file_ = core->typeLetter(type_) + PIStringAscii(".dat"); - file_size = 0; - switch (type) { - case CDType::cdK: - CONNECTU(core, K_Sended, this, sended); - CONNECTU(core, K_SendFail, this, sendFailed); - CONNECTU(core, K_Received, this, received); - CONNECTU(core, K_ReceiveFail, this, receiveFailed); - CONNECTU(core, K_ChangedGlobal, this, changedGlobal); - break; - case CDType::cdX: - CONNECTU(core, X_Sended, this, sended); - CONNECTU(core, X_SendFail, this, sendFailed); - CONNECTU(core, X_Received, this, received); - CONNECTU(core, X_ReceiveFail, this, receiveFailed); - CONNECTU(core, X_ChangedGlobal, this, changedGlobal); - break; - case CDType::cdC: - CONNECTU(core, C_Sended, this, sended); - CONNECTU(core, C_SendFail, this, sendFailed); - CONNECTU(core, C_Received, this, received); - CONNECTU(core, C_ReceiveFail, this, receiveFailed); - CONNECTU(core, C_ChangedGlobal, this, changedGlobal); - break; - case CDType::cdM: - CONNECTU(core, M_Sended, this, sended); - CONNECTU(core, M_SendFail, this, sendFailed); - CONNECTU(core, M_Received, this, received); - CONNECTU(core, M_ReceiveFail, this, receiveFailed); - CONNECTU(core, M_ChangedGlobal, this, changedGlobal); - break; - default: break; - } -} - - -bool Interface::test(int v) { - return s->test(v); -} - - -CDType & Interface::operator [](const PIString & name_) { - return (*s)[name_]; -} - - -const CDType Interface::operator [](const PIString & name_) const { - return (*s)[name_]; -} - - -CDType & Interface::operator [](const PIDeque & path_) { - return (*s)[path_]; -} - - -const CDType Interface::operator [](const PIDeque & path_) const { - return (*s)[path_]; -} - - -CDType & Interface::operator [](int v) { - //piCout << (void*)this << "[]" << core; - return (*s)[v]; -} - - -const CDType Interface::operator [](int v) const { - //piCout << (void*)this << "[]" << core; - return (*s)[v]; -} - - -CDSection & Interface::section(int v) { -// CDSection & ret = s->section(v); -// piCout << "[get section]" << v << ret.name; - return s->section(v); -} - - -const CDSection Interface::section(int v) const { - return s->section(v); -} - - -CDSection & Interface::section(const PIDeque &path) { - PIDeque spath = path; - CDSection * rs = s; - while (!spath.isEmpty()) { - rs = &(rs->section(spath.take_front())); - } - return *rs; -} - - -CDSection & Interface::root() { - return *s; -} - - -const CDSection & Interface::root() const { - return *s; -} - - -int Interface::count(bool recursive) const { - return s->count(recursive); -} - - -bool Interface::exists(PIDeque path) const { - return s->exists(path); -} - - -void Interface::setFileName(const PIString & _file) { - file_ = _file; -} - - -bool Interface::configure(const PIString & config) { - PIConfig conf(config, PIIODevice::ReadOnly); - PIConfig::Entry & e(conf.getValue(core->typeLetter(s->cd_type_))); - bool ret = false; - setFileName(e.getValue("file", file(), &ret).toString()); - return ret; -} - - -void Interface::reinitConnection(const PIString & configuration) { - core->init(configuration); -} - - -void Interface::releaseConnection() { - core->release(); -} - - -void Interface::write(PIIODevice * d) { - core->cd_write(s, d); -} - - -void Interface::read(PIIODevice * d) { - core->cd_read(s, d); -} - - -void Interface::parse(PIIODevice * d) { - core->cd_parse(s, d); -} - - -void Interface::update(PIIODevice * d, UpdateModeFlags mode) { - core->cd_update(s, d, mode); -} - - -void Interface::calculate() { - core->cd_calculate(s); -} - - -PIString Interface::appConfig() { - return core->appConfig(); -} - - -PIString Interface::pultConfig() { - return core->pultConfig(); -} - - -void Interface::readFile() { - if (file_.isEmpty()) return; - PIFile f(file_, PIIODevice::ReadOnly); - read(&f); - file_size = f.size(); -} - - -void Interface::writeFile() { - if (file_.isEmpty()) return; - PIFile f(file_, PIIODevice::ReadWrite); - f.clear(); - write(&f); - file_size = f.size(); -} - - -bool Interface::inProgress() { - return core->inProgress(); -} - - -void Interface::send() { - core->send(type); -} - - -void Interface::request() { - core->request(type); -} diff --git a/cd_utils/cdutils_interface.h b/cd_utils/cdutils_interface.h deleted file mode 100644 index 635ed1d..0000000 --- a/cd_utils/cdutils_interface.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - CD Utils - Control-Debug utilites - - Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef CDUTILS_INTERFACE_H -#define CDUTILS_INTERFACE_H - -#include "cdutils_types.h" -#include "piobject.h" -#include "cd_utils_export.h" - - -namespace CDUtils { - -class CDCore; - - -class CD_UTILS_EXPORT Interface: public PIObject -{ - PIOBJECT(CDUtils::Interface) -public: - Interface(CDType::cdT type_); - - bool test(int v); - CDType & operator [](int v); - const CDType operator [](int v) const; - CDType & operator [](const PIString & name_); - const CDType operator [](const PIString & name_) const; - CDType & operator [](const PIDeque & path_); - const CDType operator [](const PIDeque & path_) const; - CDSection & section(int v); - const CDSection section(int v) const; - CDSection & section(const PIDeque & path); - CDSection & root(); - const CDSection & root() const; - - int count(bool recursive = true) const; - const PIString file() const {return file_;} - int fileSize() const {return file_size;} - CDType::cdT cdType() const {return type;} - bool exists(PIDeque path) const; - - void setFileName(const PIString & _file); - bool configure(const PIString & config); - void reinitConnection(const PIString & configuration); - void releaseConnection(); - void write(PIIODevice * d); - void read(PIIODevice * d); - void parse(PIIODevice * d); - void update(PIIODevice * d, UpdateModeFlags mode = SaveByName); - void calculate(); - - PIString appConfig(); - PIString pultConfig(); - - void readFile(); - void writeFile(); - bool inProgress(); - - EVENT(sended) - EVENT(sendFailed) - EVENT(received) - EVENT(receiveFailed) - EVENT(changedGlobal) - EVENT_HANDLER(void, send); - EVENT_HANDLER(void, request); - -protected: - CDCore * core; - CDSection * s; - CDType::cdT type; - PIString file_; - int file_size; - -}; - - -} - - -#endif // CDUTILS_INTERFACE_H diff --git a/cd_utils/cdutils_k.cpp b/cd_utils/cdutils_k.cpp deleted file mode 100644 index 6ee850a..0000000 --- a/cd_utils/cdutils_k.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "cdutils_k.h" -#include "cdutils_core.h" - -using namespace CDUtils; - -KInterface K; - - -KInterface::KInterface(): Interface(CDType::cdK) { -} - - -void KInterface::directChange(const CDType & k) { - core->K_DirectChange(k.path(), k.value()); -} - - -void KInterface::directChange(const CDType & k, double v) { - core->K_DirectChange(k.path(), PIString::fromNumber(v)); -} diff --git a/cd_utils/cdutils_k.h b/cd_utils/cdutils_k.h deleted file mode 100644 index a3190f1..0000000 --- a/cd_utils/cdutils_k.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - CD Utils - Control-Debug utilites - - Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef CDUTILS_K_H -#define CDUTILS_K_H - -#include "cdutils_interface.h" -#include "cd_utils_export.h" - - -namespace CDUtils { - - -class CD_UTILS_EXPORT KInterface: public Interface -{ - PIOBJECT_SUBCLASS(KInterface, Interface) -public: - KInterface(); - - EVENT1(keepNamesRequest, bool*, kn) - - void directChange(const CDType & k); - void directChange(const CDType & k, double v); - -}; - -} - -extern CD_UTILS_EXPORT CDUtils::KInterface K; - -#endif // CDUTILS_K_H diff --git a/cd_utils/cdutils_m.cpp b/cd_utils/cdutils_m.cpp deleted file mode 100644 index cd326cd..0000000 --- a/cd_utils/cdutils_m.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "cdutils_m.h" -#include "cdutils_core.h" - -using namespace CDUtils; - -MInterface M; - - -MInterface::MInterface(): Interface(CDType::cdM) { - CONNECTU(core, M_Message, this, messageReceived); -} - - -void MInterface::messageBox(const CDType & m, const PIString & msg) { - core->sendMessage(m, MessageBox, msg); -} - - -PICout MInterface::createPICout(const CDType & m) const { - PIString * buff = new PIString("[" + CDCore::pathToString(m.path()) + "]"); - return PICout(buff, 1); -} diff --git a/cd_utils/cdutils_m.h b/cd_utils/cdutils_m.h deleted file mode 100644 index 2585b66..0000000 --- a/cd_utils/cdutils_m.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - CD Utils - Control-Debug utilites - - Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef CDUTILS_M_H -#define CDUTILS_M_H - -#include "cdutils_interface.h" -#include "cd_utils_export.h" - - -namespace CDUtils { - - -class CD_UTILS_EXPORT MInterface: public Interface -{ - PIOBJECT_SUBCLASS(MInterface, Interface) -public: - MInterface(); - - PICout operator [](int v) {return createPICout((*s)[v]);} - PICout operator [](int v) const {return createPICout((*s)[v]);} - PICout operator [](const PIString & name_) {return createPICout((*s)[name_]);} - PICout operator [](const PIString & name_) const {return createPICout((*s)[name_]);} - PICout operator [](const PIDeque & path_) {return createPICout((*s)[path_]);} - PICout operator [](const PIDeque & path_) const {return createPICout((*s)[path_]);} - - void messageBox(const CDType & m, const PIString & msg); - - EVENT3(messageReceived, PIDeque, path, int, type, PIString, msg) - -private: - PICout createPICout(const CDType & m) const; - -}; - -} - -extern CD_UTILS_EXPORT CDUtils::MInterface M; - -#endif // CDUTILS_M_H diff --git a/cd_utils/cdutils_parser.cpp b/cd_utils/cdutils_parser.cpp deleted file mode 100644 index 50e0600..0000000 --- a/cd_utils/cdutils_parser.cpp +++ /dev/null @@ -1,196 +0,0 @@ -#include "cdutils_parser.h" -#include "cdutils_types.h" -#include "piiostring.h" -#include "piiobytearray.h" -#include "pifile.h" - -using namespace CDUtils; - -enum Phase { - eName = 1, - eBracketOpen, - eBracketClose, - eMemberName, - eMemberEqual, - eMemberValue, - eMemberComma, - eComment, - eMultiComment -}; - - -void removeComment(PIString & line, PIString * type, PIString * comment) { - int ci = line.find("//"); - if (ci >= 0) { - if (comment) *comment = line.right(line.size_s() - ci - 2); - line.cutRight(line.size_s() - ci).trim(); - if (type && comment && !line.isEmpty()) { - *type = comment->takeLeft(1); - comment->trim(); - } - } -} - - -void parseEnumLine(PIString & line, int * value, PIString * type, PIString * comment) { - removeComment(line, type, comment); - int ci = line.find("="); - if (ci >= 0) { - if (value) *value = line.right(line.size_s() - ci - 1).trim().toInt(); - line.cutRight(line.size_s() - ci).trim(); - } - if (line.trim().endsWith(",")) line.cutRight(1); -} - - -void parseInsert(PIString line, PIString & alias, PIStringList & out) { - out.clear(); - int ci = line.find("="); - if (ci < 0) return; - alias = line.right(line.size_s() - ci - 1).trim(); - line.cutRight(line.size_s() - ci).trim(); - while (line.find("[") > 0) { - int is = line.find("["), ie = line.find("]"); - PIString arr = line.mid(is + 1, ie - is - 1); - out << arr; - line.cutMid(is, ie - is + 1); - } - if (!line.isEmpty()) out.insert(0, line); -} - - -PIVector enumValues(const PIString & e, const PIMap & sections, PIStringList & enames) { - PIVector ret; - enames.clear(); - if (sections.contains(e)) { - ret = sections[e].indexes(); - enames = sections[e].index_names(); - } else { - int v = e.toInt(); - if (v < 2) return ret; - for (int i = 0; i < v; ++i) { - ret << i; - enames << "";//PIString::fromNumber(i); - } - } - return ret; -} - - -CDSection CDParser::parse(PIIODevice * d, int cdsection_type) { - CDType::cdT et = (CDType::cdT)cdsection_type; - if (!d) return CDSection(et); - if (!d->canRead()) return CDSection(et); - //piCout << "[CDSection] parse start"; - CDSection cs(et); - CDType ck; - PIMap sections; - PIMap enum_values; - PIString content, line, alias, type, comment; - PIStringList iarr; - if (PIStringAscii(d->className()) == PIStringAscii("PIFile")) { - PIByteArray c = ((PIFile*)d)->readAll(); - c << uchar(0); - content = PIString::fromUTF8((const char *)c.data()); - } - if (PIStringAscii(d->className()) == PIStringAscii("PIIOString")) content = *(((PIIOString*)d)->string()); - if (PIStringAscii(d->className()) == PIStringAscii("PIIOByteArray")) content = PIString(*(((PIIOByteArray*)d)->byteArray())); - PIIOString ios(&content); - //int phase = 0; - int cind = -1; - while ((cind = content.find("enum", cind)) >= 0) { - ios.seek(cind); - line = ios.readLine().trim(); - type.clear(); - comment.clear(); - removeComment(line, &type, &comment); - if (line.find("{") < 0) { - cind += 4; - continue; - } - line.cutLeft(line.find("enum") + 4).trim(); - line.cutRight(line.size_s() - line.find("{")).trim(); - if (line.isEmpty()) { - cind += 4; - continue; - } - cs = CDSection(et); - cs.name = line; - //piCout << "enum" << cs.name; - int cev = 0; -// cevalues.clear(); - while (!ios.isEnd()) { - line = ios.readLine().trim(); - comment.clear(); - removeComment(line, &type, &comment); - if (line.find("}") >= 0) break; - if (line.isEmpty()) { - if (comment.find("=") >= 0) { - parseInsert(comment, alias, iarr); - if (!iarr.isEmpty()) { -// piCout << "#" << enum_values; - if (!enum_values.contains(alias)) { - piCout << "Parse error: can`t find section alias \"" << alias << "\"!"; - return CDSection(et); - } - if (!sections.contains(iarr.front())) { - piCout << "Parse error: can`t find section \"" << iarr.front() << "\"!"; - return CDSection(et); - } - //piCout << "insert" << alias << iarr; - int aval = enum_values.value(alias); - CDSection is = sections.value(iarr.take_front()), ts; - int ibpos = is.name.size_s(); - piForeachRC (PIString & a, iarr) { - PIStringList enames; - PIVector evals = enumValues(a, sections, enames); - //piCout << a << evals; - for (int i = 0; i < evals.size_s(); ++i) { - ts.section(evals[i]) = is; - ts.section(evals[i]).alias = enames[i]; - } - ts.name = is.name; - ts.name.insert(ibpos, PIString("[") << a << "]"); - is = ts; - ts = CDSection(et); - } - is.alias = alias; - cs.section(aval) = is; - } - } - } else { - parseEnumLine(line, &cev, &type, &comment); - //piCout << line << "=" << cev << "//" << type << comment; - ck = CDType(cev, line, type, "", "", comment, et); - if (type == "e") { - if (comment.startsWith("${")) { - comment.cutLeft(1); - PIString en = comment.inBrackets('{', '}'); - comment.cutLeft(en.size_s() + 2).trim(); - ck.setEnumValues(sections.value(en).enumValues()); - ck.setComment(comment); - //piCout << "enum" << en << ck.enumValues(); - } - } - cs[cev] = ck; - //cevalues[line] = cev; - enum_values[line] = cev; - ++cev; - } - } - //piCout << cs.name << cs.k; - sections[cs.name] = cs; -// piCout << "#" << cevalues; -// enum_values << cevalues; - cind += 4; - } -// piCout << "[CDSection] parse end"; - switch (et) { - case CDType::cdK: return sections.value("KDescription"); - case CDType::cdX: return sections.value("XDescription"); - case CDType::cdC: return sections.value("CDescription"); - case CDType::cdM: return sections.value("MDescription"); - default: return CDSection(et); - } - return CDSection(et); -} diff --git a/cd_utils/cdutils_parser.h b/cd_utils/cdutils_parser.h deleted file mode 100644 index 4b23fa3..0000000 --- a/cd_utils/cdutils_parser.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - CD Utils - Control-Debug utilites - - Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef CDUTILS_PARSER_H -#define CDUTILS_PARSER_H - -#include "cd_utils_export.h" - -class PIIODevice; - -namespace CDUtils { - -class CDSection; - -namespace CDParser { - -CD_UTILS_EXPORT CDSection parse(PIIODevice * d, int cdsection_type); - -} - -} - -#endif // CDUTILS_PARSER_H diff --git a/cd_utils/cdutils_protocol.h b/cd_utils/cdutils_protocol.h deleted file mode 100644 index c9b541c..0000000 --- a/cd_utils/cdutils_protocol.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - CD Utils - Control-Debug utilites - - Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef CDUTILS_PROTOCOL_H -#define CDUTILS_PROTOCOL_H - -#include "pistring.h" -#include "cd_utils_export.h" - -namespace CDUtils { - - enum CDPacketType { - CD_Ping, - CD_Pong, - - CD_KQuery, - CD_KSend, - CD_KDirectChange, - - CD_XQuery, - CD_XSend, - CD_XRequest, - CD_XValues, - - CD_CQuery, - CD_CSend, - CD_Command, - - CD_MQuery, - CD_MSend, - CD_Message, - }; - -# pragma pack(push,1) - - struct CD_UTILS_EXPORT PacketHeader { - int type; // CDPacketType - int session_id; - }; - - struct CD_UTILS_EXPORT PacketKDirectChange { - PIDeque path; - PIString value; - }; - -# pragma pack(pop) - - -inline PIByteArray & operator <<(PIByteArray & s, const PacketHeader & v) {s << v.type << v.session_id; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PacketHeader & v) {s >> v.type >> v.session_id; return s;} - -inline PIByteArray & operator <<(PIByteArray & s, const PacketKDirectChange & v) {s << v.path << v.value; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PacketKDirectChange & v) {s >> v.path >> v.value; return s;} - -} - -#endif // CDUTILS_PROTOCOL_H diff --git a/cd_utils/cdutils_types.cpp b/cd_utils/cdutils_types.cpp deleted file mode 100644 index 2000e1e..0000000 --- a/cd_utils/cdutils_types.cpp +++ /dev/null @@ -1,762 +0,0 @@ -#include "cdutils_types.h" -#include "piconfig.h" -#include "pifile.h" -#include "pievaluator.h" -#include "cdutils_core.h" - -using namespace CDUtils; - -//int cdtype_debug_cnt = 1; - -const int cd_x_history_max_size = 4000; - -CDType::CDType() { - index_ = -1; - value_d = 0.; - value_i = 0; - value_b = calculated = x_enabled = false; - cd_type_ = cdNull; - parent = 0; - avg_size = 1; - mode_ = rmode_ = X_Current; -// debug_cnt = cdtype_debug_cnt; -// cdtype_debug_cnt++; -// piCout << "[CDType]" << "create Null" << debug_cnt; -} - - - - -CDType::CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t) { - index_ = i; - name_ = n.trimmed(); - type_ = t.trimmed(); - value_s = v.trimmed(); - formula_ = f.trimmed(); - comment_ = c.trimmed(); - value_d = v.toDouble(); - value_i = v.toInt(); - value_b = v.toBool(); - cd_type_ = cd_t; - calculated = x_enabled = false; - parent = 0; - avg_size = 1; - mode_ = rmode_ = X_Current; - if (type_ == "e") { - enum_values = parseEnumComment(comment_); -// piCout << enum_values.size() << enum_values; - } -// piCout << type_.size() << type_.toUTF8(); -// piCout << formula_.size() << formula_.toUTF8(); -// piCout << comment_.size() << comment_.toUTF8(); -// debug_cnt = cdtype_debug_cnt; -// cdtype_debug_cnt++; -// piCout << "[CDType] create" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK); -} - - -CDType & CDType::operator =(double x) { - value_d = x; - value_i = x; - value_b = x > 0.; - if (mode_ == X_All_Avg) { - avg_h << x; - double val = 0; - if (avg_h.size_s() >= avg_size) { - for (int i = 0; i < avg_h.size_s(); i++) - val += avg_h[i]; - val /= avg_h.size(); - avg_h.clear(); - if (history.size() < cd_x_history_max_size) - history << val; - } - } - return *this; -} - - -PIString CDType::type() const { - if (type_.trimmed().isEmpty()) return "f"; - // piCout << "type =" << type_.trimmed() << ";" << type_ << "#"; - return type_; -} - - -PIString CDType::value() const { - if (type_ == "b") return PIString::fromBool(value_b); - return value_s; -} - - -PIVariant CDType::variantValue() const { - if (type_.isEmpty()) return PIVariant(value()); - switch (type_[0].toAscii()) { - case 'b': return PIVariant(toBool()); break; - case 'n': return PIVariant(toInt()); break; - case 'f': return PIVariant(toDouble()); break; - case 'c': return PIVariant(PIVariantTypes::Color(toInt())); break; - case 'e': { - PIVariantTypes::Enum e = enum_values; - e.selectValue(toInt()); - return PIVariant(e); - break; - } - default: break; - } - return PIVariant(value()); -} - - -void CDType::setValue(const PIString & value_) { - formula_ = value_; - value_d = formula_.toDouble(); - value_i = formula_.toInt(); - value_b = formula_.toBool(); -} - - -void CDType::setVariantValue(const PIVariant & value_) { - setValue(PIString::fromNumber(value_.toDouble())); -} - - -void CDType::setFormula(const PIString & f) { - formula_ = f; - calculated = false; - //PIEvaluator e; - //calculate(&e); -} - - -PIStringList CDType::pathString() const { - PIStringList ret; - CDSection * ps = CDCore::instance()->root(cd_type_); - if (!ps) return ret; - for (int i = 0; i < path_.size_s() - 1; ++i) { - ps = &(ps->section(path_[i])); - if (!ps->alias.isEmpty()) ret << ps->alias; - else ret << PIString::fromNumber(path_[i]); - } - if (!name_.isEmpty()) ret << name_; - else ret << PIString::fromNumber(index_); - return ret; -} - - -void CDType::readX(PIByteArray & ba) { - if (ba.size() < 5) return; - uchar t(0); ba >> t; - rmode_ = (XMode)t; - switch (rmode_) { - case X_Current: - ba >> value_d; - break; - case X_All_Avg: { - PIVector ah; - ba >> ah; - history << ah; - if (!history.isEmpty()) - value_d = history.back(); - } break; - default: break; - } - value_i = value_d; - value_b = value_d > 0.; -} - - -void CDType::writeX(PIByteArray & ba) { - ba << uchar(mode_); - switch (mode_) { - case X_Current: - ba << value_d; - break; - case X_All_Avg: - ba << history; - history.clear(); - break; - default: break; - } -} - - -bool CDType::calculate(PIEvaluator * e, PIVector stack) { - if (stack.contains(this)) { - error_ = "Circular dependencies: "; - piForeachC (CDType * k, stack) - error_ << k->name() << " -> "; - error_ << name(); - //piCout << error_; - return false; - } - stack << this; - if (calculated) return true; - calculated = true; - error_.clear(); - if (!parent) return true; - //piCout << "calc" << name_ << (parent ? parent->alias : "root"); - value_s = formula_.trimmed(); - for (;;) { - int ki = value_s.find("K["); - if (ki < 0) break; - int ke = value_s.find("]", ki + 2); - if (ke < 0) break; - PIString kp = value_s.mid(ki + 2, ke - ki - 2); - //piCout << kp; - CDType & k((*parent)[kp]); - k.calculate(e, stack); - value_s.replace(ki, ke - ki + 1, PIString::fromNumber(k.value_d)); - } - value_d = formula_.toDouble(); - value_i = formula_.toInt(); - value_b = formula_.toBool(); - double ev = 0.; - if (!e->check(value_s) && value_d == 0. && value_i == 0 && !value_b) { - PIString f = formula_.trimmed().toLowerCase(); - if (f != "off" && f != "false" && f != "no" && !value_b) { - error_ = e->error(); - return false; - } - } else - if (e->isCorrect()) - ev = e->evaluate().real(); - //piCout << value_s << value_i << value_d << ev; - //if ((value_d == 0.) || (piAbsd(value_d) < piAbsd(ev))) value_d = ev; - //if ((value_i == 0) || (piAbsd(value_i) < piAbsd(ev))) value_i = int(ev); - if ((value_d == 0.) || (ev != 0.)) value_d = ev; - if ((value_i == 0) || (ev != 0.)) value_i = int(ev); - value_b = value_b || (ev > 0.); - if (value_i != 0) { - if (value_d == 0.) value_d = value_i; - value_b = value_i > 0; - } - if (value_d != 0.) { - if (value_i == 0) value_i = value_d; - value_b = value_d > 0.; - } - if (value_b) { - if (value_d == 0.) value_d = 1.; - if (value_i == 0) value_i = 1; - } - value_s = PIString::fromNumber(value_d); - return true; -} - - -PIVariantTypes::Enum CDType::parseEnumComment(PIString c) { - PIVariantTypes::Enum ret; - if (c.isEmpty()) return ret; - if (type_ == "e") { - PIStringList sl = c.inBrackets('{', '}').split(","); - int cval = 0; - piForeach (PIString & s, sl) { - s.trim(); - if (s.isEmpty()) continue; - if (s[0].isDigit()) { - int ind = s.find("-"); - if (ind > 0) { - cval = s.left(ind).toInt(); - s.cutLeft(ind + 1).trim(); - } - } - ret << PIVariantTypes::Enumerator(cval, s); - ++cval; - } - } - //piCout << c << "=" << ret; - return ret; -} - - -//CDType::CDType(const CDType &cdt) { -// index_ = cdt.index_; -// name_ = cdt.name_; -// type_ = cdt.type_; -// value_s = cdt.value_s; -// formula_ = cdt.formula_; -// comment_ = cdt.comment_; -// value_d = cdt.value_d; -// value_i = cdt.value_i; -// value_b = cdt.value_b; -// cd_type_ = cdt.cd_type_; -// debug_cnt = cdtype_debug_cnt; -// cdtype_debug_cnt++; -// piCout << "[CDType] copy" << debug_cnt << "->" << cdt.debug_cnt << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK); -//} - - -//CDType &CDType::operator =(const CDType &cdt) { -// index_ = cdt.index_; -// name_ = cdt.name_; -// type_ = cdt.type_; -// value_s = cdt.value_s; -// formula_ = cdt.formula_; -// comment_ = cdt.comment_; -// value_d = cdt.value_d; -// value_i = cdt.value_i; -// value_b = cdt.value_b; -// cd_type_ = cdt.cd_type_; -// piCout << "[CDType] assign" << debug_cnt << "=" << cdt.debug_cnt << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK); -// //debug_cnt = cdt.debug_cnt; -// return *this; -//} - - -//CDType::~CDType() { -// piCout << "[CDType] delete" << debug_cnt << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK); -//} - - - -CDSection::CDSection(CDType::cdT type_) { - cd_type_ = type_; - null.cd_type_ = type_; -} - - -CDSection & CDSection::section(int v) { - CDSection & ret(s[v]); - ret.cd_type_ = cd_type_; - return ret; -} - - -const CDSection CDSection::section(int v) const { - CDSection & ret(s[v]); - ret.cd_type_ = cd_type_; - return s[v]; -} - - -bool CDSection::exists(PIDeque path) const { - if (path.isEmpty()) return false; - if (path.size_s() == 1) return cd.contains(path[0]); - int si = path[0]; - if (!s.contains(si)) return false; - path.remove(0, 1); - return s[si].exists(path); -} - - -int CDSection::count(bool recursive) const { - int ret = cd.size_s(); - if (recursive) { - PIMap::const_iterator i; - for (i = s.constBegin(); i != s.constEnd(); ++i) - ret += i->second.count(recursive); - } - return ret; -} - - -int CDSection::sectionsCount() const { - return s.size(); -} - - -PIStringList CDSection::index_names() const { - PIStringList ret; - auto i = cd.makeIterator(); - while (i.next()) - ret << i.value().name(); - return ret; -} - - -void CDSection::calculate() { - prepareCalculate(); - if (cd_type_ != CDType::cdK) return; - PIEvaluator e; - calculateRecursive(&e); -} - - -CDType & CDSection::getByName(const PIString & name_) { - PIStringList np = name_.split("."); - if (np.isEmpty()) return null; - //piCout << np; - CDSection * cs = this, * ns = 0; - if (np.front().isEmpty()) { - if (np.size_s() < 2) return null; - cs = CDCore::instance()->root(cd_type_); - np.pop_front(); - } - for (int i = 0; i < np.size_s() - 1; ++i) { - if (np[i].isEmpty()) return null; - bool isd = np[i][0].isDigit() || (np[i][0] == '-'); - int dv = 0; - if (isd) dv = np[i].toInt(); - ns = 0; - auto it = cs->s.makeIterator(); - while (it.next()) { - bool f = false; - if (isd) f = (dv == it.key()); - else f = (np[i] == it.value().alias); - //piCout << "s..." << it.key() << it.value().alias << f; - if (f) { - ns = &(it.valueRef()); - break; - } - } - //piCout << ns; - if (!ns) return null; - cs = ns; - } - if (np.back().isEmpty()) return null; - bool isd = np.back()[0].isDigit() || (np.back()[0] == '-'); - int dv = 0; - if (isd) dv = np.back().toInt(); - //piCout << np.back() << isd << dv; - auto it = cs->cd.makeIterator(); - while (it.next()) { - bool f = false; - if (isd) f = (dv == it.key()); - else f = (np.back() == it.value().name()); - //piCout << "k..." << it.key() << it.value().name() << f; - if (f) - return cs->cd[it.key()]; - } - return null; -} - - -CDType & CDSection::getByPath(const PIDeque & path_) { - if (path_.isEmpty()) return null; - CDSection * s = this; - for (int i = 0; i < path_.size_s() - 1; ++i) - s = &(s->section(path_[i])); - if (!s) return null; - return (*s)[path_.back()]; -} - - -void CDSection::write(PIIODevice * d, const PIString & prefix) { - if (!d) return; - if (cd.isEmpty() && s.isEmpty()) return; -// piCout << "[CDSection] write start"; - PIString l; - PIStringList cdtl; - cdtl << "null" << "k" << "x" << "c" << "m"; - if (prefix.isEmpty()) l = "[" + cdtl[cd_type_] + "]"; - else l = "[" + prefix + "." + cdtl[cd_type_] + "]"; - l += "\n"; - d->write(l.toUTF8()); - l = "name = " + name + " \n"; - d->write(l.toUTF8()); - l = "alias = " + alias + " \n"; - d->write(l.toUTF8()); - auto i = cd.makeIterator(); - while (i.next()) { - const CDType & ck(i.value()); - if (ck.cd_type() != cd_type_) continue; - switch (cd_type_) { - case CDType::cdNull: break; - case CDType::cdK: - l.clear(); l << ck.index() << ".f = " << ck.formula() << " #s " << ck.comment() << " \n"; - d->write(l.toUTF8()); - l.clear(); l << ck.index() << ".v = " << ck.value() << " #" << ck.type() << " " << ck.name() << " \n"; - d->write(l.toUTF8()); - if (!ck.enumValues().enum_list.isEmpty()) { - l.clear(); l << ck.index() << ".ev = {"; - //PIVector el = ck.enumValues(); - piForeachC (PIVariantTypes::Enumerator & e, ck.enumValues().enum_list) - l << e.value << " - " << e.name << ", "; - l.cutRight(2); - l << "} \n"; - d->write(l.toUTF8()); - } - break; - case CDType::cdX: - l.clear(); l << ck.index() << ".name = " << ck.name() << " #s " << ck.comment() << " \n"; - d->write(l.toUTF8()); - l.clear(); l << ck.index() << ".mode = " << ck.xmode() << " #e (0 - cur, 1 - all_avg) " << "\n"; - d->write(l.toUTF8()); - l.clear(); l << ck.index() << ".avg = " << ck.avg() << " #n " << "\n"; - d->write(l.toUTF8()); - l.clear(); l << ck.index() << ".sel = " << (ck.isSelectedX() ? "1" : "0") << " #n " << "\n"; - d->write(l.toUTF8()); - break; - case CDType::cdC: - case CDType::cdM: - l.clear(); l << ck.index() << ".name = " << ck.name() << " #s " << ck.comment() << " \n"; - d->write(l.toUTF8()); - break; - } - } - if (!s.isEmpty()) { - if (prefix.isEmpty()) l = "s"; - else l = prefix + ".s"; - auto j = s.makeIterator(); - while (j.next()) { - j.valueRef().write(d, l + "." + PIString::fromNumber(j.key())); - } - } - if (prefix.isEmpty()) { - l = "[]\n"; - d->write(l.toUTF8()); - } -// piCout << "[CDSection] write end"; -} - - -void CDSection::read(const void * ep) { -// piCout << "[CDSection] read start"; - PIStringList cdtl; - cdtl << "null" << "k" << "x" << "c" << "m"; - cd.clear(); - s.clear(); - PIConfig::Entry & e(*(PIConfig::Entry*)ep); - name = e.getValue(cdtl[cd_type_] + ".name").value(); - alias = e.getValue(cdtl[cd_type_] + ".alias").value(); - PIConfig::Entry & cdl = e.getValue(cdtl[cd_type_]); - for (int i = 0; i < cdl.childCount(); ++i) { - const PIConfig::Entry * e(cdl.child(i)); - bool ok = false; - int id = e->name().toInt(-1, &ok); -// piCout << "[read]" << ke->name() << ke->value() << ok; -// PIString n = ke->getValue("v").comment(); -// PIString t = n.takeLeft(1); - if (ok) { - CDType c; - PIString ev; - switch (cd_type_) { - case CDType::cdNull: break; - case CDType::cdK: - c = CDType(id, e->getValue("v").comment(), e->getValue("v").type(), e->getValue("v").value(), e->getValue("f").value(), e->getValue("f").comment(), cd_type_); - ev = e->getValue("ev", "").value(); - if (!ev.isEmpty()) - c.enum_values = c.parseEnumComment(ev); - break; - case CDType::cdX: - c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString() , e->getValue("name").comment(), cd_type_); - c.setXMode((CDType::XMode)e->getValue("mode", int(CDType::X_Current)).value().toInt()); - c.setAvg((CDType::XMode)e->getValue("avg", 1).value().toInt()); - c.x_enabled = e->getValue("sel", false).value().toBool(); - break; - case CDType::cdC: - case CDType::cdM: - c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString() , e->getValue("name").comment(), cd_type_); - break; - } - cd[id] = c; - } - } - PIConfig::Entry & sl = e.getValue("s"); - for (int i = 0; i < sl.childCount(); ++i) { - const PIConfig::Entry * se(sl.child(i)); - int sid = se->name().toInt(); - CDSection & rs(s[sid]); - rs.cd_type_ = cd_type_; - rs.read(se); - } -// piCout << "[CDSection] read end"; -} - - -void CDSection::update(CDSection & v, UpdateModeFlags mode) { - if (mode[SaveByIndex] && mode[SaveByName]) { - piCout << "[CDSection] update error: SaveByIndex | SaveByName mode is denied!"; - return; - } - //piCout << "[CDSection] update start"; - //piCout << "before" << k.size() << v.k.size(); - - PIMap prev_cd_f_bi; - PIMap prev_cd_f_bn; - PIMap::iterator i; - if (mode[SaveByIndex]) { - for (i = cd.begin(); i != cd.end(); ++i) - prev_cd_f_bi[i.key()] = i.value().formula(); - } - if (mode[SaveByName]) { - for (i = cd.begin(); i != cd.end(); ++i) - prev_cd_f_bn[i.value().name_] = i.value().formula(); - } - if (!mode[Merge]) - cd.clear(); - for (i = v.cd.begin(); i != v.cd.end(); ++i) { - int id = i.key(); - PIString n = i.value().name(); - cd[id] = i.value(); - if (mode[SaveByIndex]) { - if (prev_cd_f_bi.contains(id)) - cd[id].setFormula(prev_cd_f_bi[id]); - } - if (mode[SaveByName]) { - if (prev_cd_f_bn.contains(n)) - cd[id].setFormula(prev_cd_f_bn[n]); - } - } - - PIMap prev_s_bi; - PIMap prev_s_bn; - PIMap::iterator j; - if (mode[SaveByIndex]) { - for (j = s.begin(); j != s.end(); ++j) - prev_s_bi[j.key()] = j.value(); - } - if (mode[SaveByName]) { - for (j = s.begin(); j != s.end(); ++j) - prev_s_bn[j.value().alias] = j.value(); - } - if (!mode[Merge]) - s.clear(); - for (j = v.s.begin(); j != v.s.end(); ++j) { - int id = j.key(); - PIString n = j.value().alias; - s[id] = j.value(); - if (mode[SaveByIndex]) { - if (prev_s_bi.contains(id)) - s[id] = prev_s_bi[id]; - } - if (mode[SaveByName]) { - if (prev_s_bn.contains(n)) - s[id] = prev_s_bn[n]; - } - s[id].update(j.value(), mode); - } - - /*PISet used; - for (i = k.begin(); i != k.end(); ++i) { - if (v.k.contains(i.key())) { - PIString f = k[i.key()].formula_; - CDType & cdt = v.k[i.key()]; - cdt.formula_ = f; - k[i.key()] = cdt; - used << i.key(); - } - if (mode) { - CDType & ck(k[i.key()]); - if (prev_k_f_bn.contains(ck.name_)) - ck.setFormula(prev_k_f_bn[ck.name_]); - } - } - //piCout << " after" << k.size(); - for (i = v.k.begin(); i != v.k.end(); ++i) { - if (!used.contains(i.key())) - k[i.key()] = i.value(); - CDType & ck(k[i.key()]); - ck.setFormula(prev_k_f_bn.value(ck.name_)); - } - used.clear(); - PIMap::iterator j; - for (j = s.begin(); j != s.end(); ++j) { - if (v.s.contains(j.key())) - j.value().update(v.s[j.key()], mode); - used << j.key(); - } - for (j = v.s.begin(); j != v.s.end(); ++j) { - if (!used.contains(j.key())) - s[j.key()] = j.value(); - }*/ -// piCout << "[CDSection] update end"; -} - - -bool CDSection::isSameStructure(CDSection & v) { - PIMap cd_ids; - PIMap::iterator i; - for (i = cd.begin(); i != cd.end(); ++i) - cd_ids[i.value().name()] = i.key(); - for (i = v.cd.begin(); i != v.cd.end(); ++i) { - if (!cd_ids.contains(i.value().name())) continue; - //piCout << i.key() << k[i.key()].name() << i.value().name(); - if (cd[cd_ids[i.value().name()]].index() != i.key()) - return false; - } - PIMap::iterator j; - for (j = v.s.begin(); j != v.s.end(); ++j) { - if (!s.contains(j.key())) continue; - if (!s[j.key()].isSameStructure(j.value())) - return false; - } - return true; -} - - -void CDSection::prepareCalculate() { - PIMap::iterator i; - for (i = cd.begin(); i != cd.end(); ++i) { - i.value().parent = this; - i.value().calculated = false; - } - PIMap::iterator j; - for (j = s.begin(); j != s.end(); ++j) - j.value().prepareCalculate(); -} - - -void CDSection::calculateRecursive(PIEvaluator * e) { - PIMap::iterator i; - for (i = cd.begin(); i != cd.end(); ++i) - i.value().calculate(e); - PIMap::iterator j; - for (j = s.begin(); j != s.end(); ++j) - j.value().calculateRecursive(e); -} - - -void CDSection::setSelectedX(bool yes) { - PIMap::iterator i; - for (i = cd.begin(); i != cd.end(); ++i) - i.value().x_enabled = yes; - PIMap::iterator j; - for (j = s.begin(); j != s.end(); ++j) - j.value().setSelectedX(yes); -} - - -PIVector > CDSection::collectX() const { - PIVector > ret; - PIMap::const_iterator i; - for (i = cd.begin(); i != cd.end(); ++i) { - if (i.value().x_enabled) - ret << i.value().path(); - } - PIMap::const_iterator j; - for (j = s.constBegin(); j != s.constEnd(); ++j) - ret << j.value().collectX(); - return ret; -} - - -void CDSection::makePath(PIDeque p) { - PIDeque tp; - PIMap::iterator i; - for (i = cd.begin(); i != cd.end(); ++i) { - tp = p; - tp << i.key(); - i.value().path_ = tp; - //piCout << "path for" << i.value().name() << tp; - } - PIMap::iterator j; - for (j = s.begin(); j != s.end(); ++j) { - tp = p; - tp << j.key(); - j.value().makePath(tp); - } -} - - -PIVector CDSection::children(bool recursive) const { - PIVector ret; - PIMap::const_iterator i; - for (i = cd.begin(); i != cd.end(); ++i) - ret << const_cast(&(i.value())); - if (!recursive) return ret; - PIMap::const_iterator j; - for (j = s.constBegin(); j != s.constEnd(); ++j) - ret << j.value().children(true); - return ret; -} - - -PIVariantTypes::Enum CDSection::enumValues() const { - PIVariantTypes::Enum ret; - PIMap::const_iterator i; - for (i = cd.constBegin(); i != cd.constEnd(); ++i) - ret << PIVariantTypes::Enumerator(i.key(), i.value().name()); - return ret; -} - - diff --git a/cd_utils/cdutils_types.h b/cd_utils/cdutils_types.h deleted file mode 100644 index 299e4a9..0000000 --- a/cd_utils/cdutils_types.h +++ /dev/null @@ -1,193 +0,0 @@ -/* - CD Utils - Control-Debug utilites - - Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef CDUTILS_TYPES_H -#define CDUTILS_TYPES_H - -#include "pistring.h" -#include "pimap.h" -#include "pivariant.h" -#include "cd_utils_export.h" - -class PIIODevice; -class PIEvaluator; -class CD_Pult; -class CDItem; -class CDItemModel; - -namespace CDUtils { - -class CDSection; - -enum UpdateMode { - SaveByIndex = 0x01, - SaveByName = 0x02, - Merge = 0x04 -}; - -enum MessageType { - Log = 1, - MessageBox, -}; - -typedef PIFlags UpdateModeFlags; - -class CD_UTILS_EXPORT CDType { - friend class CDSection; - friend class CDCore; - friend class Interface; - friend class XInterface; -public: - enum cdT {cdNull, cdK, cdX, cdC, cdM}; - enum XMode {X_Current, X_All_Avg}; - - CDType(); - CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t); - - CDType & operator =(double x); - int index() const {return index_;} - PIString name() const {return name_;} - PIString type() const; - PIString value() const; - PIVariant variantValue() const; - PIString formula() const {return formula_;} - PIString comment() const {return comment_;} - double toDouble() const {return value_d;} - int toInt() const {return value_i;} - bool toBool() const {return value_b;} - cdT cd_type() const {return cd_type_;} - void setValue(const PIString & value_); - void setVariantValue(const PIVariant & value_); - void setFormula(const PIString & formula); - void setComment(const PIString & comment) {comment_ = comment;} - operator double() const {return value_d;} - const PIVariantTypes::Enum & enumValues() const {return enum_values;} - void setEnumValues(const PIVariantTypes::Enum & ev) {enum_values = ev;} - const PIString & errorString() const {return error_;} - PIDeque path() const {return path_;} - PIStringList pathString() const; - - void setXMode(XMode mode) {mode_ = mode;} - void setAvg(int avg) {avg_size = avg;} - XMode xmode() const {return mode_;} - XMode xmode_rec() const {return rmode_;} - int avg() const {return avg_size;} - bool isSelectedX() const {return x_enabled;} - void readX(PIByteArray & ba); - void writeX(PIByteArray & ba); - - PIVector history; - -protected: - bool calculate(PIEvaluator * e, PIVector stack = PIVector()); - PIVariantTypes::Enum parseEnumComment(PIString c); - cdT cd_type_; - int index_; - PIString name_, type_; - PIString value_s, formula_, comment_, error_; - PIVariantTypes::Enum enum_values; - CDSection * parent; - PIDeque path_; - double value_d; - int value_i; - bool value_b, calculated, x_enabled; - PIVector avg_h; - int avg_size; - XMode mode_, rmode_; -}; - - -class CD_UTILS_EXPORT CDSection { - friend class CDCore; - friend class Interface; - friend class XInterface; - friend class ::CD_Pult; - friend class ::CDItem; - friend class ::CDItemModel; -public: - - CDSection(CDType::cdT type_ = CDType::cdNull); - - bool test(int v) {return cd.value(v).toBool();} -// CDType & operator [](int v) {if (!k.contains(v)) k[v].index_ = v; return k[v];} - CDType & operator [](int v) {return cd[v];} - const CDType operator [](int v) const {return cd[v];} - CDType & operator [](const PIString & name_) {return getByName(name_);} - const CDType operator [](const PIString & name_) const {return const_cast(this)->getByName(name_);} - CDType & operator [](const PIDeque & path_) {return getByPath(path_);} - const CDType operator [](const PIDeque & path_) const {return const_cast(this)->getByPath(path_);} - CDSection & section(int v); - const CDSection section(int v) const; - - bool isEmpty() const {return cd.isEmpty() && s.isEmpty();} - bool exists(PIDeque path) const; - int count(bool recursive = true) const; - int sectionsCount() const; - PIVector indexes() const {return cd.keys();} - PIStringList index_names() const; - void calculate(); - void makePath(PIDeque p = PIDeque()); - PIVector children(bool recursive = true) const; - PIVariantTypes::Enum enumValues() const; - - PIString name; - PIString alias; - -protected: - CDSection(PIMap k_, PIMap s_) { - cd = k_; - s = s_; - } - CDType & getByName(const PIString & name_); - CDType & getByPath(const PIDeque & path_); - void write(PIIODevice * d, const PIString & prefix = PIString()); - void read(const void * ep); - void update(CDSection & v, UpdateModeFlags mode = SaveByName); - bool isSameStructure(CDSection & v); - void prepareCalculate(); - void calculateRecursive(PIEvaluator * e); - void setSelectedX(bool yes); - PIVector > collectX() const; - - PIMap cd; - mutable PIMap s; - CDType null; - CDType::cdT cd_type_; -}; - -} - - -inline PICout operator <<(PICout s, const CDUtils::CDType & v) { - s.space(); - s.setControl(0, true); - switch (v.cd_type()) { - case CDUtils::CDType::cdK : s << "K["; break; - case CDUtils::CDType::cdX : s << "X["; break; - case CDUtils::CDType::cdC : s << "C["; break; - case CDUtils::CDType::cdM : s << "M["; break; - default : s << "Null["; break; - } - s << v.name() << "(" << v.index() << ")] = " << v.value(); - s.restoreControl(); - return s; -} - - -#endif // CDUTILS_TYPES_H diff --git a/cd_utils/cdutils_x.cpp b/cd_utils/cdutils_x.cpp deleted file mode 100644 index 2b2d24a..0000000 --- a/cd_utils/cdutils_x.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "cdutils_x.h" -#include "cdutils_core.h" - -using namespace CDUtils; - -XInterface X; - - -XInterface::XInterface(): Interface(CDType::cdX) { - CONNECTU(core, X_ReceivedX, this, receivedX); -} - - -void XInterface::setEnabled(const CDType & x, bool en) { - core->x_mutex.lock(); - CDType & t((*s)[x.path()]); - if (t.cd_type() != CDType::cdX) { - core->x_mutex.unlock(); - return; - } - t.x_enabled = en; - //piCout << t << "x_enabled" << en; - core->need_rebuild_x = true; - core->x_mutex.unlock(); -} - - -PIVector > XInterface::enabledList() const { - return CDCore::instance()->x_selected; -} - - -void XInterface::setEnabledList(const PIVector > & l) { - CDCore::instance()->x_selected = l; -} - - -void XInterface::lock() { - CDCore::instance()->x_mutex.lock(); -} - - -void XInterface::unlock() { - CDCore::instance()->x_mutex.unlock(); -} - - -void XInterface::start(double freq) { - core->startX(freq); -} - - -void XInterface::stop() { - core->stopX(); -} diff --git a/cd_utils/cdutils_x.h b/cd_utils/cdutils_x.h deleted file mode 100644 index b0a8e3c..0000000 --- a/cd_utils/cdutils_x.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - CD Utils - Control-Debug utilites - - Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef CDUTILS_X_H -#define CDUTILS_X_H - -#include "cdutils_interface.h" -#include "cd_utils_export.h" - - -namespace CDUtils { - - -class CD_UTILS_EXPORT XInterface: public Interface -{ - PIOBJECT_SUBCLASS(XInterface, Interface) -public: - XInterface(); - - EVENT1(keepNamesRequest, bool*, xn) - EVENT1(receivedX, PIVector >, pathes) - - void enable(const CDType & x) {setEnabled(x, true);} - void disable(const CDType & x) {setEnabled(x, false);} - void setEnabled(const CDType & x, bool en); - void setDisabled(const CDType & x, bool dis) {setEnabled(x, !dis);} - PIVector > enabledList() const; - void setEnabledList(const PIVector > & l); - void lock(); - void unlock(); - - void start(double freq = 20.); - void stop(); - -}; - -} - -extern CD_UTILS_EXPORT CDUtils::XInterface X; - -#endif // CDUTILS_X_H diff --git a/cd_utils/cdutilstest.cpp b/cd_utils/cdutilstest.cpp deleted file mode 100644 index ff35970..0000000 --- a/cd_utils/cdutilstest.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include "cdutils_k.h" -#include "cdutils_x.h" -#include "cdutils_c.h" -#include "cdutils_m.h" -#include "cdutils_core.h" -#include "cdtest.h" -#include "pip.h" -#include "k_description.h" - -using namespace CDUtils; - -class Core : public PIObject -{ - PIOBJECT(Core) - public: - Core() { - CDCore::instance()->initApp(); -// piCout << "testCore"; - CONNECTU(&timer, tickEvent, this, timerDone); - CONNECTU(&X, received, this, xrecv); - CONNECTU(&C, received, this, crecv); - t = 0.; - } - - void load() { - rf.open("k.dat", PIIODevice::ReadWrite); - K.read(&rf); - rf.close(); - } - - void save() { - rf.open("k_out.txt", PIIODevice::ReadWrite); - rf.resize(0); - K.write(&rf); - rf.close(); -// rf.open("k_out.txt", PIIODevice::ReadWrite); -// K.read(&rf); -// rf.close(); -// rf.open("k_out2.txt", PIIODevice::ReadWrite); -// rf.resize(0); -// K.write(&rf); -// rf.close(); -// rf.open("k_out2.txt", PIIODevice::ReadWrite); -// K.read(&rf); -// rf.close(); -// rf.open("k_out3.txt", PIIODevice::ReadWrite); -// rf.resize(0); -// K.write(&rf); -// rf.close(); - } - - void test() { - X.lock(); - X[KD::Frequency] = 100; - X.section(KD::Spectrometer)[KD::Temperature_default] = sin(t); - t += 0.01; - X.unlock(); - /*piCout << "count" << K.count(); - piCout << K[First]; - piCout << K[Second];*/ - } - - EVENT_HANDLER(void, ksend) {piCout << "sended k";} - EVENT_HANDLER(void, crecv) { - piCout << "received c"; - C.connect(C.section(KD::Logs).section(KD::Spec).section(KD::Formats)[KD::Binary], this, HANDLER(cmd)); - C.autoConnect(this); - } - EVENT_HANDLER(void, xrecv) { - piCout << "received x"; - if (!timer.isRunning()) timer.start(10); - X.start(); - } - EVENT_HANDLER(void, timerDone) {test();} - EVENT_HANDLER(void, cmd) {piCout << "command cmd";} - EVENT_HANDLER(void, c_Pause) { - piCout << "command pause"; - M[KD::Main] << "rec command" << C[KD::Pause]; - M.messageBox(M.root()[KD::Core], "init successfull"); - } - EVENT_HANDLER(void, c_Spectrometer_Connection) {piCout << "command spec_conn";} - -private: - PIFile rf; - PITimer timer; - double t; -}; - - -int main(int argc, char *argv[]) { - X.start(); - piSleep(1); - //CDCore::instance()->destroy(); - piCout << "DELETED"; - return 0; -} - diff --git a/cd_utils/k_description.h b/cd_utils/k_description.h deleted file mode 100644 index 09d53ce..0000000 --- a/cd_utils/k_description.h +++ /dev/null @@ -1,147 +0,0 @@ -#ifndef K_DESCRIPTION_H -#define K_DESCRIPTION_H - -namespace KD { - -enum Sections { - Startup, - Spectrometer, - Switch, - Formats, - Logs, - Detector, - CoreOutput, -}; - -enum LogFormat { - Text, //b text - Binary, //b binary -}; - -enum LogType { - Data, //b write data logs - Spec, //b write spectrogram logs - ARINC, //b ARINC -}; - -enum KLogConfig { - // LogFormat = Formats - StartupWrite, //b - ApplyBinaryLogHeader, //b Apply settings under ID = 255 for binary log - MaximumWriteFrequency, //f Maximum frequency for log in Hz, or 0 for unlimited -}; - -enum SwitchType { - BaySpec, - DiCon, -}; - -enum SpectrometerConnection { - TCP, - USB, -}; - -enum PeakSearchMode { - Left, - Max, - Right, -}; - -enum CoreMode { - ModeSpectrometer, - ModePlayer, - ModePeaks, -}; - -enum KSpectrometer { - Connection, //e ${SpectrometerConnection} - Temperature_compensation, //b Use temperature sensor or default temperature witout compensation - Temperature_default, //f Default temperature using if compensation disabled -}; - -enum KSwitch { - Enabled, //b 0 or 1 Use optical switch or not - Wait, //n Delay after switching channel, ms - Autoscan, //e {0 - scan with our forces, 1 - SDK autoscan} - Autoscan_offset, //n Offset for SDK autoscan - Type, //e ${SwitchType} -}; - -enum KDetector { - Threshold_Min, //f - Threshold_Max, //f - SideSize, //f - SideOffset, //f - PeaksSearch, //e ${PeakSearchMode} -}; - -enum KCoreOutput { - SendSpectrum, //b Send spectrum data or empty vector - SendOnlyCurrentValue, //b Send current values or all stored in 20Hz -}; - -enum CoreOutputChannel { - GUI, - SecGUI, - ThirdGUI, -}; - -enum KDescription { - // KSpectrometer = Spectrometer - // KSwitch = Switch - // KDetector = Detector - // KCoreOutput[CoreOutputChannel] = CoreOutput - // KLogConfig[LogType] = Logs - Gratings_history, //n Gratings peak values history, count - Amplitude_history_size, //n Count of history values to calculate sensors amplitude - Fourier_enabled, //b Global fourier enable flag - Fourier_size, //n Size of fourier window, in counts - Fourier_YScale, //f scale for fourier amplitude - Fourier_Max_or_Density, //n 0 - Maximum in fourier window, 1 - Density of fourier window - Mode, //e ${CoreMode} Work mode - SynchronizationEnabled, //b When enabled, start logs and reset time when sync signal received - SynchronizationMode, //e {0 - disabled, 1 - new file, 2 - column in log} - LambdasAutoReset, //b Set lambdas_0 to grating values on first data receive - Gauss_size, //n - //Peak_max_offset, //f in pixels - //Peak_LF_coeff, //f 1. - no filtering - GratingOverloadMax, //n - GratingOverloadMin, //n - SendLED, //b Send to LED Arduino serial port current state - SynchronizationClearValues, //b clear gratings and sensors values and history on sync - PeaksModeFrequency, //f - PeaksModeAdditionNm_1, //f Addition nm to peaks in ModePeaks, channel 1 - PeaksModeAdditionNm_2, //f Addition nm to peaks in ModePeaks, channel 2 - PeaksModeAdditionNm_3, //f Addition nm to peaks in ModePeaks, channel 3 - PeaksModeAdditionNm_4, //f Addition nm to peaks in ModePeaks, channel 4 -}; - -enum XDescription { - // KSpectrometer = Spectrometer - // KSwitch = Switch - // KDetector = Detector - // KCoreOutput[CoreOutputChannel] = CoreOutput - // KLogConfig[LogType] = Logs - State, //b - Frequency, //n cur freq - //Fourier_enabled, //b Global fourier enable flag -}; - -enum CDescription { - // KSpectrometer = Spectrometer - // KCoreOutput[CoreOutputChannel] = CoreOutput - // KLogConfig[LogType] = Logs - Halt, //b - Reboot, //n cur freq - Pause, //b Global fourier enable flag -}; - -enum MDescription { - Main, //b - Core, //s - Warnings, //b Global fourier enable flag -}; - -} - -#endif // K_DESCRIPTION_H diff --git a/qad/cmake/FindQAD.cmake b/cmake/FindQAD.cmake similarity index 100% rename from qad/cmake/FindQAD.cmake rename to cmake/FindQAD.cmake diff --git a/qad/cmake/QADMacros.cmake b/cmake/QADMacros.cmake similarity index 100% rename from qad/cmake/QADMacros.cmake rename to cmake/QADMacros.cmake diff --git a/qad/cmake/QtWraps.cmake b/cmake/QtWraps.cmake similarity index 96% rename from qad/cmake/QtWraps.cmake rename to cmake/QtWraps.cmake index eac40ee..da1df24 100644 --- a/qad/cmake/QtWraps.cmake +++ b/cmake/QtWraps.cmake @@ -1,811 +1,811 @@ -#[[ - -find_qt([ ...] [Qt4] [Qt5]) - -Find Qt4 or/and Qt5 packages -If Qt4/5 found, set -* Qt<4/5>_ROOT var to Qt root dir -* Qt<4/5>_BIN var to Qt binary dir -* Qt<4/5>_PLUGINS_DIR var to Qt plugins dir -* Qt<4/5>_LANG_DIR var to Qt translations dir - - - - -qt_sources( [NO_DEFAULT] [DIR ] [ ...]) - -Collect all sources, optionally in directory and -Additional filters . By default filter files with regexps -"*.h", "*.hpp", "*.c", "*.cpp", "*.ui", "*.qrc", "*.rc", "*.ts" and "lang/*.ts". -Default filters disabled with option NO_DEFAULT - - - - -qt_wrap( ... [HDRS ] [CPPS ] [QMS ]) - -Prepare sources for compile -Store headers to , all wrapped Qt4 files to _Qt4 and Qt5 files to _Qt5 -version are automatic detected after find_qt() call - - - - -qt_add_executable( [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] source1 [source2 ...]) - -Add executables for founded Qt versions, target names is -All needed Qt includes automatic added to corresponding targets - cant be CPPS variable passed to qt_wrap() or some list or filename - - - - -qt_add_library( [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] source1 [source2 ...]) - -Add library for founded Qt versions, target names is -All needed Qt includes automatic added to corresponding targets - cant be CPPS variable passed to qt_wrap() or some list or filename - - - - -qt_target_link_libraries( ... ...) - -Link targets for founded Qt versions, target names is -All needed Qt libraries automatic added to corresponding targets -if QT_MULTILIB_LIST contains some linking library, to it name automatic -add or individual libname<_SUFFIX_Qt?> - - - - -qt_target_compile_definitions( ...) - -Syntax similar to original "target_compile_definitions()" -Specify compile definitions to use when compiling a given - - - - -qt_target_include_directories( ...) - -Syntax similar to original "target_include_directories()" -Add include directories to a target - - - - -qt_install(...) - -Syntax similar to original "install()" -Install targets for founded Qt versions - -if DESTINATION set to "QtBin" files will be installed -to corresponding Qt binary directory -if DESTINATION set to "QtLang" files will be installed -to corresponding Qt translation directory -if DESTINATION starts with "QtPlugins" files will be installed -to corresponding Qt plugins directory - -Add LANG type for first argument - in this case you should -specify variable name, not variable value! -e.g. "qt_install(LANG my_QM DESTINATION QtLang)" - - - - -qt_install_lang( DESTINATION [PATHS [] [...] ]) - -Search Qt translations for all dependencies -in Qt_LANG_DIR for _LANG languages -and install them to . PATH are additional search paths. -You should use "set_lang()" macro before this action - - - - -qt_get_target( [Qt4 | Qt5]) - -Write real Qt target name to -If Qt4 or Qt5 specified, search for this version, -otherwise returns greatest version - - - - -qt_get_targets( ) - -Write all real Qt target names to - - - - -qt_generate_export_header( ...) - -Call generate_export_header on Qt multitarget - - -]] - - -cmake_policy(SET CMP0011 NEW) # don`t affect includer policies -cmake_policy(SET CMP0020 NEW) # Automatically link Qt executables to qtmain target on Windows -if (POLICY CMP0057) - cmake_policy(SET CMP0057 NEW) # Support if() IN_LIST -endif() -if (POLICY CMP0074) - cmake_policy(SET CMP0074 OLD) # ignore _ROOT variables -endif() -set(__qt_bug_modules "UiTools") - - -set(_QT_VERSIONS_ 4 5) -foreach(_v ${_QT_VERSIONS_}) - if (NOT DEFINED TARGET_SUFFIX_Qt${_v}) - set(TARGET_SUFFIX_Qt${_v} "${_v}") - set(MULTILIB_SUFFIX_Qt${_v} "${_v}") - endif() - set(MOC_INC_Qt${_v}) -endforeach() -if (NOT DEFINED QT_MULTILIB_LIST) - set(QT_MULTILIB_LIST) -endif() -#set(TARGET_SUFFIX_Qt4 "") - - -macro(find_qt) - set(_QCOMP) - foreach(_v ${_QT_VERSIONS_}) - set(_NEED${_v} 0) - set(LOCAL_FOUND${_v} 0) - set(MOC_INC_Qt${_v}) - set(Qt${_v}_INCLUDES) - set(Qt${_v}_LIBRARIES) - set(Qt${_v}_ROOT) - set(Qt${_v}_BIN) - set(Qt${_v}_PLUGINS_DIR) - set(Qt${_v}_LANG_DIR) - endforeach() - set(_NEED_SOME 0) - set(_QUIET) - foreach(_i ${ARGN}) - set(_FOUND_NEED 0) - foreach(_v ${_QT_VERSIONS_}) - if ("x${_i}" STREQUAL "xQt${_v}") - set(_NEED${_v} 1) - set(_NEED_SOME 1) - set(_FOUND_NEED 1) - endif() - if ("x${_i}" STREQUAL "xQUIET") - set(_QUIET QUIET) - endif() - endforeach() - if (NOT _FOUND_NEED) - list(APPEND _QCOMP "${_i}") - endif() - endforeach() - if (NOT _NEED_SOME) - foreach(_v ${_QT_VERSIONS_}) - set(_NEED${_v} 1) - endforeach() - endif() - list(REMOVE_DUPLICATES _QCOMP) - if (_NEED4) - find_package(Qt4 ${_QUIET}) - if (Qt4_FOUND) - set(LOCAL_FOUND4 1) - get_filename_component(Qt4_BIN ${QT_QMAKE_EXECUTABLE} PATH) - set(Qt4_INCLUDES ${QT_INCLUDES}) - foreach(m ${_QCOMP}) - string(TOUPPER "${m}" _um) - #message("${QT_QT${_um}_FOUND}") - if (${QT_QT${_um}_FOUND}) - list(APPEND Qt4_LIBRARIES ${QT_QT${_um}_LIBRARY}) - endif() - endforeach() - set(Qt4_PLUGINS_DIR ${QT_PLUGINS_DIR}) - set(Qt4_LANG_DIR ${Qt4_BIN}/../translations) - set(Qt4_ROOT "${Qt4_BIN}/../") - endif() - endif() - if (_NEED5) - #set(_MSG 1) - #if (Qt5_FOUND) - # set(_MSG 0) - #endif() - find_package(Qt5 COMPONENTS Core LinguistTools UiPlugin Widgets ${_QCOMP} ${_QUIET}) - if (DEFINED ANDROID_PLATFORM) - set(CMAKE_SHARED_MODULE_SUFFIX_CXX ".so") - set(CMAKE_SHARED_LIBRARY_SUFFIX_CXX ".so") - set(CMAKE_SHARED_MODULE_SUFFIX_C ".so") - set(CMAKE_SHARED_LIBRARY_SUFFIX_C ".so") - endif() - if (Qt5_FOUND) - set(LOCAL_FOUND5 1) - set(_Qt5Modules) - foreach(m ${_QCOMP}) - if (${Qt5${m}_FOUND}) - set(__lib ${Qt5${m}_LIBRARIES}) - if (DEFINED ANDROID_PLATFORM) - if (m IN_LIST __qt_bug_modules) - get_target_property(__lib Qt5::${m} LOCATION) - endif() - endif() - list(APPEND _Qt5Modules ${m}) - list(APPEND Qt5_INCLUDES ${Qt5${m}_INCLUDE_DIRS}) - list(APPEND Qt5_LIBRARIES ${__lib}) - endif() - endforeach() - #get_property(_up_dir TARGET Qt5::UiPlugin PROPERTY INTERFACE_INCLUDE_DIRECTORIES) - #message("${_up_dir}") - #if (NOT "x${_up_dir}" STREQUAL "x") - # list(APPEND Qt5_INCLUDES ${_up_dir}) - #endif() - get_target_property(_Qt5_qmake Qt5::qmake LOCATION) - get_filename_component(Qt5_BIN ${_Qt5_qmake} PATH) - foreach(_p ${Qt5Gui_PLUGINS}) - get_target_property(_l ${_p} LOCATION) - get_filename_component(_l ${_l} DIRECTORY) - string(FIND "${_l}" "/" _ind REVERSE) - string(SUBSTRING "${_l}" 0 ${_ind} _l) - set(Qt5_PLUGINS_DIR ${_l}) - #message("Qt5: plugins dir: ${Qt5_PLUGINS_DIR}") - break() - endforeach() - string(FIND "${Qt5_BIN}" "/" _ind REVERSE) - string(SUBSTRING "${Qt5_BIN}" 0 ${_ind} Qt5_ROOT) - if ("x${Qt5_PLUGINS_DIR}" STREQUAL "x") - set(Qt5_PLUGINS_DIR "${Qt5_ROOT}/plugins") - endif() - if (APPLE) - list(APPEND MOC_INC_Qt5 "-F${Qt5_ROOT}/lib") - endif() - set(Qt5_LANG_DIR ${Qt5_BIN}/../translations) - if (NOT _QT5_MSG) - message(STATUS "Found Qt5: ${_Qt5_qmake} (version \"${Qt5_VERSION}\")") - set(_QT5_MSG 1 CACHE BOOL "msg_qt5" FORCE) - #message(STATUS "Found Qt5 modules: ${_Qt5Modules}") - endif() - endif() - endif() - foreach(_v ${_QT_VERSIONS_}) - if (LOCAL_FOUND${_v}) - foreach(_p ${Qt${_v}_INCLUDES}) - list(APPEND MOC_INC_Qt${_v} "-I${_p}") - #message("${_p}") - endforeach() - endif() - #message("${MOC_INC_Qt${_v}}") - endforeach() - -endmacro() - - -macro(qt_sources OUT) - set(${OUT}) - set(_DIR "") - set(_IS_DIR 0) - set(_NO_DEFAULT 0) - set(_DEFAULT) - set(_REGEXP) - set(_REGEXP_WD) - foreach(_i ${ARGN}) - if (_IS_DIR) - set(_DIR "${_i}") - set(_IS_DIR 0) - elseif ("x${_i}" STREQUAL "xDIR") - set(_IS_DIR 1) - elseif ("x${_i}" STREQUAL "xNO_DEFAULT") - set(_NO_DEFAULT 1) - else() - list(APPEND _REGEXP ${_i}) - endif() - endforeach() - if (NOT "x${_DIR}" STREQUAL "x") - #file(TO_CMAKE_PATH "${_DIR}//" _DIR) - string(REPLACE "\\" "/" _DIR "${_DIR}/") - string(REPLACE "//" "/" _DIR "${_DIR}") - endif() - foreach(_i ${_REGEXP}) - list(APPEND _REGEXP_WD "${_DIR}${_i}") - endforeach() - if (NOT _NO_DEFAULT) - set(_DEFAULT "${_DIR}*.h" "${_DIR}*.hpp" "${_DIR}*.c" "${_DIR}*.cpp" "${_DIR}*.ui" "${_DIR}*.qrc" "${_DIR}*.rc" "${_DIR}*.ts" "${_DIR}lang/*.ts") - endif() - #message("${_DEFAULT}, ${_REGEXP_WD}") - file(GLOB ${OUT} ${_DEFAULT} ${_REGEXP_WD}) -endmacro() - - -macro(qt_wrap) - set(HDR_VAR) - set(CPP_VAR) - set(QM_VAR) - set(_HDR_ARG 0) - set(_CPP_ARG 0) - set(_QM_ARG 0) - set(WAS_HDR_ARG 0) - set(WAS_CPP_ARG 0) - set(WAS_QM_ARG 0) - set(FILE_LIST) - foreach(_i ${ARGN}) - if (_HDR_ARG) - set(HDR_VAR ${_i}) - set(WAS_HDR_ARG 1) - set(_HDR_ARG 0) - elseif (_CPP_ARG) - set(CPP_VAR ${_i}) - set(WAS_CPP_ARG 1) - set(_CPP_ARG 0) - elseif (_QM_ARG) - set(QM_VAR ${_i}) - set(WAS_QM_ARG 1) - set(_QM_ARG 0) - elseif ("x${_i}" STREQUAL "xHDRS") - set(_HDR_ARG 1) - elseif ("x${_i}" STREQUAL "xCPPS") - set(_CPP_ARG 1) - elseif ("x${_i}" STREQUAL "xQMS") - set(_QM_ARG 1) - else() - list(APPEND FILE_LIST "${_i}") - endif() - endforeach() - foreach(_v ${_QT_VERSIONS_}) - set(CPP${_v}_VAR) - set(QM${_v}_VAR) - if (LOCAL_FOUND${_v}) - if (WAS_CPP_ARG) - set(CPP${_v}_VAR ${CPP_VAR}_Qt${_v}) - endif() - if (WAS_QM_ARG) - set(QM${_v}_VAR ${QM_VAR}_Qt${_v}) - endif() - endif() - endforeach() - #message("found 4: ${LOCAL_FOUND4}, 5: ${LOCAL_FOUND5}") - #message("has HRDS: ${WAS_HDR_ARG}: ${HDR_VAR}") - #message("has CPPS4: ${WAS_CPP_ARG}: ${CPP4_VAR}") - #message("has CPPS5: ${WAS_CPP_ARG}: ${CPP5_VAR}") - #message("files: ${FILE_LIST}") - set(H_LIST) - set(CPP_LIST) - set(UI_LIST) - set(RES_LIST) - set(RC_LIST) - set(TS_LIST) - foreach(_i ${FILE_LIST}) - get_filename_component(_EXT "${_i}" EXT) - #message("${_EXT}") - if (NOT ("x${_EXT}" STREQUAL "x")) - if (("x${_EXT}" STREQUAL "x.h") OR ("x${_EXT}" STREQUAL "x.hpp")) - list(APPEND H_LIST "${_i}") - #message("header") - endif() - if (("x${_EXT}" STREQUAL "x.c") OR ("x${_EXT}" STREQUAL "x.cpp") OR ("x${_EXT}" STREQUAL "x.cxx")) - list(APPEND CPP_LIST "${_i}") - #message("source") - endif() - if ("x${_EXT}" STREQUAL "x.ui") - list(APPEND UI_LIST "${_i}") - endif() - if ("x${_EXT}" STREQUAL "x.qrc") - list(APPEND RES_LIST "${_i}") - endif() - if ("x${_EXT}" STREQUAL "x.rc") - list(APPEND RC_LIST "${_i}") - endif() - if ("x${_EXT}" STREQUAL "x.ts") - list(APPEND TS_LIST "${_i}") - endif() - endif() - endforeach() - if (WAS_HDR_ARG) - set(${HDR_VAR}) - list(APPEND ${HDR_VAR} ${H_LIST}) - endif() - set(SRC_CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) - foreach(_v ${_QT_VERSIONS_}) - if (LOCAL_FOUND${_v} AND WAS_CPP_ARG) - set(CMAKE_CURRENT_BINARY_DIR ${SRC_CMAKE_CURRENT_BINARY_DIR}/qt${_v}) - set(${CPP${_v}_VAR}) - if (WAS_QM_ARG) - set(${QM${_v}_VAR}) - endif() - set(MOCS${_v}) - set(CUIS${_v}) - set(CRES${_v}) - if (${_v} EQUAL 4) - qt4_wrap_cpp(MOCS${_v} ${H_LIST} OPTIONS -nw ${MOC_INC_Qt4}) - qt4_wrap_ui(CUIS${_v} ${UI_LIST}) - qt4_add_resources(CRES${_v} ${RES_LIST}) - if (WAS_QM_ARG) - set(${QM${_v}_VAR} "") - qt4_add_translation(${QM${_v}_VAR} ${TS_LIST}) - endif() - elseif (${_v} EQUAL 5) - qt5_wrap_cpp(MOCS${_v} ${H_LIST} OPTIONS -nw ${MOC_INC_Qt5}) - qt5_wrap_ui(CUIS${_v} ${UI_LIST}) - qt5_add_resources(CRES${_v} ${RES_LIST}) - if (WAS_QM_ARG) - set(${QM${_v}_VAR} "") - qt5_add_translation(${QM${_v}_VAR} ${TS_LIST}) - endif() - else() - # Qt6 ... - endif() - #message("${${QM${_v}_VAR}}") - list(APPEND ${CPP${_v}_VAR} ${CPP_LIST}) - list(APPEND ${CPP${_v}_VAR} ${RC_LIST}) - list(APPEND ${CPP${_v}_VAR} ${MOCS${_v}}) - list(APPEND ${CPP${_v}_VAR} ${CUIS${_v}}) - list(APPEND ${CPP${_v}_VAR} ${CRES${_v}}) - if (WAS_QM_ARG) - list(APPEND ${CPP${_v}_VAR} ${${QM${_v}_VAR}}) - endif() - #message("${${QM${_v}_VAR}}") - endif() - endforeach() - set(CMAKE_CURRENT_BINARY_DIR ${SRC_CMAKE_CURRENT_BINARY_DIR}) -endmacro() - - -macro(_qt_split_add_args _P _A) - set(${_P}) - set(${_A}) - foreach(_i ${ARGN}) - if (NOT ("x${${_i}_Qt${_v}}" STREQUAL "x")) - list(APPEND ${_A} ${${_i}_Qt${_v}}) - elseif (("x${_i}" STREQUAL "xWIN32") OR - ("x${_i}" STREQUAL "xMACOSX_BUNDLE") OR - ("x${_i}" STREQUAL "xSTATIC") OR - ("x${_i}" STREQUAL "xSHARED") OR - ("x${_i}" STREQUAL "xMODULE") OR - ("x${_i}" STREQUAL "xEXCLUDE_FROM_ALL")) - list(APPEND ${_P} ${_i}) - elseif ("x${${_i}}" STREQUAL "x") - list(APPEND ${_A} ${_i}) - else() - list(APPEND ${_A} ${${_i}}) - endif() - endforeach() -endmacro() - - -macro(__qt_set_defines _NAME _T) - target_compile_definitions(${_T} PRIVATE "__TARGET_NAME__=\"${_NAME}\"") - target_compile_definitions(${_T} PRIVATE "__TARGET_LABEL__=\"${${_NAME}_LABEL}\"") - target_compile_definitions(${_T} PRIVATE "__TARGET_COMPANY__=\"${${_NAME}_COMPANY}\"") - target_compile_definitions(${_T} PRIVATE "__TARGET_VERSION__=\"${${_NAME}_VERSION}\"") -endmacro() - - -macro(qt_add_executable _NAME) - foreach(_v ${_QT_VERSIONS_}) - if (LOCAL_FOUND${_v}) - _qt_split_add_args(_PREF _ARGS ${ARGN}) - if(APPLE) - set(_PREV_CIND "${CMAKE_INSTALL_NAME_DIR}") - set(CMAKE_INSTALL_NAME_DIR "@rpath") - else() - if(NOT WIN32) - set(CMAKE_INSTALL_RPATH "\$ORIGIN;\$ORIGIN/lib") - endif() - endif() - set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}}) - add_executable(${_TARGET} ${_PREF} ${_ARGS}) - set(_${_NAME}_is_qt 1) - target_include_directories(${_TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/qt${_v} ${Qt${_v}_INCLUDES}) - __qt_set_defines(${_NAME} ${_TARGET}) - - if(APPLE) - set(CMAKE_INSTALL_NAME_DIR "${_PREV_CIND}") - endif() - # # Apple crosscompiling rpath patch - # if (APPLE AND CMAKE_CROSSCOMPILING AND CMAKE_MACOSX_RPATH) - # foreach(_RP ${CMAKE_INSTALL_RPATH}) - # add_custom_command(TARGET ${_TARGET} POST_BUILD - # COMMAND "${CMAKE_INSTALL_NAME_TOOL}" - # "-add_rpath" "${_RP}" - # "$/$" - # COMMENT "Add to ${_TARGET} rpath \"${_RP}\"") - # endforeach() - # endif() - - #list(APPEND _ALL_TARGETS "${_TARGET}") - #set(_ALL_TARGETS ${_ALL_TARGETS} PARENT_SCOPE) - endif() - endforeach() -endmacro() - - -macro(qt_add_library _NAME) - foreach(_v ${_QT_VERSIONS_}) - if (LOCAL_FOUND${_v}) - _qt_split_add_args(_PREF _ARGS ${ARGN}) - if(APPLE) - set(_PREV_CIND "${CMAKE_INSTALL_NAME_DIR}") - set(CMAKE_INSTALL_NAME_DIR "@rpath") - else() - if(NOT WIN32) - set(CMAKE_INSTALL_RPATH "\$ORIGIN;\$ORIGIN/lib") - endif() - endif() - set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}}) - add_library(${_TARGET} ${_PREF} ${_ARGS}) - set(_${_NAME}_is_qt 1) - target_include_directories(${_TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/qt${_v} ${Qt${_v}_INCLUDES}) - __qt_set_defines(${_NAME} ${_TARGET}) - #message("add lib: \"${_TARGET}\"") - - if(APPLE) - set(CMAKE_INSTALL_NAME_DIR "${_PREV_CIND}") - endif() - # # Apple crosscompiling rpath patch - # if (APPLE AND CMAKE_CROSSCOMPILING AND CMAKE_MACOSX_RPATH) - # foreach(_RP ${CMAKE_INSTALL_RPATH}) - # add_custom_command(TARGET ${_TARGET} POST_BUILD - # COMMAND "${CMAKE_INSTALL_NAME_TOOL}" - # "-add_rpath" "${_RP}" - # "$/$" - # COMMENT "Add to ${_TARGET} rpath \"${_RP}\"") - # endforeach() - # endif() - - list(APPEND _ALL_TARGETS "${_TARGET}") - set(_ALL_TARGETS ${_ALL_TARGETS} PARENT_SCOPE) - endif() - endforeach() -endmacro() - - -macro(_qt_multitarget_suffix_ _OUT _IN _v) - string(REPLACE ":" "_" _in_str "${_IN}") - if (NOT "x${MULTILIB_${_in_str}_SUFFIX_Qt${_v}}" STREQUAL "x") - set(${_OUT} "${MULTILIB_${_in_str}_SUFFIX_Qt${_v}}") - else() - set(${_OUT} "${MULTILIB_SUFFIX_Qt${_v}}") - endif() -endmacro() - - -macro(qt_target_link_libraries _NAME) - foreach(_v ${_QT_VERSIONS_}) - if (LOCAL_FOUND${_v}) - set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}}) - set(_ARGS) - foreach(_i ${ARGN}) - set(_ind -1) - list(FIND QT_MULTILIB_LIST "${_i}" _ind) - if (_ind GREATER -1) - _qt_multitarget_suffix_(_TS ${_i} ${_v}) - #message(STATUS "${_i} in MULTILIB_LIST, suffix = ${_TS}") - list(APPEND _ARGS ${_i}${_TS}) - else() - list(APPEND _ARGS ${_i}) - endif() - endforeach() - target_link_libraries(${_TARGET} ${Qt${_v}_LIBRARIES} ${_ARGS}) - #message("link ${_TARGET}: ${Qt${_v}_LIBRARIES} ${_ARGS}") - endif() - endforeach() -endmacro() - - -macro(qt_target_compile_definitions _NAME) - foreach(_v ${_QT_VERSIONS_}) - if (LOCAL_FOUND${_v}) - set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}}) - target_compile_definitions(${_TARGET} ${ARGN}) - endif() - endforeach() -endmacro() - - -macro(qt_target_include_directories _NAME) - foreach(_v ${_QT_VERSIONS_}) - if (LOCAL_FOUND${_v}) - set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}}) - target_include_directories(${_TARGET} ${ARGN}) - endif() - endforeach() -endmacro() - - -macro(qt_install) - set(_prev_inst) - set(__add_args) - #message("command: ${ARGN}") - foreach(_v ${_QT_VERSIONS_}) - if (LOCAL_FOUND${_v}) - set(_INST_LIST) - set(_IS_TARGET 0) - set(_IS_FILES 0) - set(_IS_DEST 0) - set(_IS_LANG 0) - set(_INVALID 0) - foreach(_i ${ARGN}) - if ("x${_i}" STREQUAL "xQtLang") - set(_IS_LANG 1) - endif() - endforeach() - foreach(_i ${ARGN}) - if (_IS_TARGET) - set(_IS_TARGET 0) - set(__target ${_i}) - if (_${_i}_is_qt) - set(__target ${_i}${TARGET_SUFFIX_Qt${_v}}) - endif() - if (DEFINED ANDROID_PLATFORM) - get_target_property(_TT ${__target} TYPE) - if ("x${_TT}" STREQUAL "xEXECUTABLE") - list(APPEND __add_args EXCLUDE_FROM_ALL) - endif() - endif() - list(APPEND _INST_LIST ${__target}) - elseif (_IS_FILES) - set(_IS_FILES 0) - if (_IS_LANG) - if (("x${${_i}_Qt${_v}}" STREQUAL "x") OR ("x${_i}" STREQUAL "xDESTINATION")) - set(_INVALID 1) - else() - list(APPEND _INST_LIST ${${_i}_Qt${_v}}) - endif() - else() - list(APPEND _INST_LIST ${_i}) - endif() - else() - if (_IS_DEST) - set(_IS_DEST 0) - if ("x${_i}" STREQUAL "xQtBin") - list(APPEND _INST_LIST "${Qt${_v}_BIN}") - elseif ("x${_i}" STREQUAL "xQtLang") - list(APPEND _INST_LIST "${Qt${_v}_LANG_DIR}") - else() - set(_ind -1) - string(FIND "${_i}" "QtPlugins" _ind) - if (_ind GREATER -1) - string(REPLACE "QtPlugins" "${Qt${_v}_PLUGINS_DIR}" _o "${_i}") - list(APPEND _INST_LIST "${_o}") - else() - string(REPLACE "\\" "/" _o "${_i}") - list(APPEND _INST_LIST ${_o}) - endif() - endif() - else() - set(_ii ${_i}) - if ("x${_i}" STREQUAL "xTARGETS") - set(_IS_TARGET 1) - elseif ("x${_i}" STREQUAL "xFILES") - set(_IS_FILES 1) - elseif ("x${_i}" STREQUAL "xDESTINATION") - set(_IS_DEST 1) - elseif ("x${_i}" STREQUAL "xLANG") - set(_IS_FILES 1) - set(_IS_LANG 1) - set(_ii "FILES") - endif() - list(APPEND _INST_LIST ${_ii}) - endif() - endif() - endforeach() - if (NOT _INVALID) - if (NOT ("x${_prev_inst}" STREQUAL "x${_INST_LIST}")) - #message("install: ${_INST_LIST}") - install(${_INST_LIST} ${__add_args}) - set(_prev_inst "${_INST_LIST}") - endif() - endif() - endif() - endforeach() -endmacro() - - -macro(qt_install_lang _NAME) - set(_prev_inst) - #message("command: ${ARGN}") - set(_PATHS) - set(_DEST) - if(CMAKE_CROSSCOMPILING) - list(APPEND _PATHS "${CMAKE_PREFIX_PATH}/lang") - endif() - set(_cur_arg) - set(__args "DESTINATION;PATHS") - foreach(_i ${ARGN}) - if (_i IN_LIST __args) - set(_cur_arg "${_i}") - elseif("${_cur_arg}" STREQUAL "DESTINATION") - set(_DEST "${_i}") - elseif("${_cur_arg}" STREQUAL "PATHS") - list(APPEND _PATHS "${_i}") - endif() - endforeach() - foreach(_v ${_QT_VERSIONS_}) - if (LOCAL_FOUND${_v}) - set(_target) - if (_${_NAME}_is_qt) - set(_target ${_NAME}${TARGET_SUFFIX_Qt${_v}}) - endif() - get_target_property(_LL ${_target} LINK_LIBRARIES) - foreach (_L ${_LL}) - get_filename_component(_libname "${_L}" NAME_WE) - #message("depend on ${_libname}") - if ("${_libname}" MATCHES "Qt${_v}::.*") - string(SUBSTRING "${_libname}" 5 -1 _libname) - string(TOLOWER "${_libname}" _libname) - #message("qt lib \"${_libname}\"") - list(APPEND _qt_libs qt${_libname}) - else() - if ("${_libname}" MATCHES "lib.*") - string(LENGTH ${_libname} _sl) - math(EXPR _sl ${_sl}-3) - string(SUBSTRING ${_libname} 3 ${_sl} _libname) - endif() - if ("${_libname}" MATCHES "qad_.*${_v}") - string(LENGTH ${_libname} _sl) - math(EXPR _sl ${_sl}-1) - string(SUBSTRING ${_libname} 0 ${_sl} _libname) - #message("qad lib \"${_libname}\"") - list(APPEND _qt_libs ${_libname}) - endif() - endif() - endforeach() - if (NOT "x${_qt_libs}" STREQUAL "x") - list(APPEND _qt_libs "qtbase") - foreach (_i ${${PROJECT_NAME}_LANG}) - foreach (_l ${_qt_libs}) - unset(_qm_path CACHE) - find_file(_qm_path "${_l}_${_i}.qm" PATHS "${Qt${_v}_LANG_DIR}" ${_PATHS} NO_DEFAULT_PATH) - if (EXISTS "${_qm_path}") - install(FILES ${_qm_path} DESTINATION "${_DEST}") - #message("qm = \"${_qm_path}\"") - endif() - endforeach() - endforeach() - endif() - endif() - endforeach() -endmacro() - - -macro(qt_get_target _NAME _OUT) - set(${_OUT}) - set(_ver) - foreach(_i ${ARGN}) - foreach(_v ${_QT_VERSIONS_}) - if ("x${_i}" STREQUAL "xQt${_v}") - set(_ver ${_v}) - break() - endif() - endforeach() - if (NOT "x${_ver}" STREQUAL "x") - break() - endif() - endforeach() - foreach(_v ${_QT_VERSIONS_}) - if (LOCAL_FOUND${_v} AND (("x${_ver}" STREQUAL "x") OR ((NOT "x${_ver}" STREQUAL "x") AND ("x${_ver}" STREQUAL "x${_v}")))) - set(${_OUT} ${_NAME}${TARGET_SUFFIX_Qt${_v}}) - endif() - endforeach() -endmacro() - - -macro(qt_get_targets _NAME _OUT) - set(${_OUT}) - foreach(_v ${_QT_VERSIONS_}) - if (LOCAL_FOUND${_v}) - list(APPEND ${_OUT} ${_NAME}${TARGET_SUFFIX_Qt${_v}}) - endif() - endforeach() -endmacro() - - -macro(qt_generate_export_header _NAME) - qt_get_target(${_NAME} _some_target) - qt_get_target(${_NAME} _targets) - foreach(_t ${_targets}) - set_target_properties(${_t} PROPERTIES DEFINE_SYMBOL ${_NAME}_EXPORTS) - endforeach() - set_target_properties(${_some_target} PROPERTIES DEFINE_SYMBOL ${_NAME}_EXPORTS) - generate_export_header(${_some_target} BASE_NAME "${_NAME}" ${ARGN}) -endmacro() +#[[ + +find_qt([ ...] [Qt4] [Qt5]) + +Find Qt4 or/and Qt5 packages +If Qt4/5 found, set +* Qt<4/5>_ROOT var to Qt root dir +* Qt<4/5>_BIN var to Qt binary dir +* Qt<4/5>_PLUGINS_DIR var to Qt plugins dir +* Qt<4/5>_LANG_DIR var to Qt translations dir + + + + +qt_sources( [NO_DEFAULT] [DIR ] [ ...]) + +Collect all sources, optionally in directory and +Additional filters . By default filter files with regexps +"*.h", "*.hpp", "*.c", "*.cpp", "*.ui", "*.qrc", "*.rc", "*.ts" and "lang/*.ts". +Default filters disabled with option NO_DEFAULT + + + + +qt_wrap( ... [HDRS ] [CPPS ] [QMS ]) + +Prepare sources for compile +Store headers to , all wrapped Qt4 files to _Qt4 and Qt5 files to _Qt5 +version are automatic detected after find_qt() call + + + + +qt_add_executable( [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] source1 [source2 ...]) + +Add executables for founded Qt versions, target names is +All needed Qt includes automatic added to corresponding targets + cant be CPPS variable passed to qt_wrap() or some list or filename + + + + +qt_add_library( [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] source1 [source2 ...]) + +Add library for founded Qt versions, target names is +All needed Qt includes automatic added to corresponding targets + cant be CPPS variable passed to qt_wrap() or some list or filename + + + + +qt_target_link_libraries( ... ...) + +Link targets for founded Qt versions, target names is +All needed Qt libraries automatic added to corresponding targets +if QT_MULTILIB_LIST contains some linking library, to it name automatic +add or individual libname<_SUFFIX_Qt?> + + + + +qt_target_compile_definitions( ...) + +Syntax similar to original "target_compile_definitions()" +Specify compile definitions to use when compiling a given + + + + +qt_target_include_directories( ...) + +Syntax similar to original "target_include_directories()" +Add include directories to a target + + + + +qt_install(...) + +Syntax similar to original "install()" +Install targets for founded Qt versions + +if DESTINATION set to "QtBin" files will be installed +to corresponding Qt binary directory +if DESTINATION set to "QtLang" files will be installed +to corresponding Qt translation directory +if DESTINATION starts with "QtPlugins" files will be installed +to corresponding Qt plugins directory + +Add LANG type for first argument - in this case you should +specify variable name, not variable value! +e.g. "qt_install(LANG my_QM DESTINATION QtLang)" + + + + +qt_install_lang( DESTINATION [PATHS [] [...] ]) + +Search Qt translations for all dependencies +in Qt_LANG_DIR for _LANG languages +and install them to . PATH are additional search paths. +You should use "set_lang()" macro before this action + + + + +qt_get_target( [Qt4 | Qt5]) + +Write real Qt target name to +If Qt4 or Qt5 specified, search for this version, +otherwise returns greatest version + + + + +qt_get_targets( ) + +Write all real Qt target names to + + + + +qt_generate_export_header( ...) + +Call generate_export_header on Qt multitarget + + +]] + + +cmake_policy(SET CMP0011 NEW) # don`t affect includer policies +cmake_policy(SET CMP0020 NEW) # Automatically link Qt executables to qtmain target on Windows +if (POLICY CMP0057) + cmake_policy(SET CMP0057 NEW) # Support if() IN_LIST +endif() +if (POLICY CMP0074) + cmake_policy(SET CMP0074 OLD) # ignore _ROOT variables +endif() +set(__qt_bug_modules "UiTools") + + +set(_QT_VERSIONS_ 4 5) +foreach(_v ${_QT_VERSIONS_}) + if (NOT DEFINED TARGET_SUFFIX_Qt${_v}) + set(TARGET_SUFFIX_Qt${_v} "${_v}") + set(MULTILIB_SUFFIX_Qt${_v} "${_v}") + endif() + set(MOC_INC_Qt${_v}) +endforeach() +if (NOT DEFINED QT_MULTILIB_LIST) + set(QT_MULTILIB_LIST) +endif() +#set(TARGET_SUFFIX_Qt4 "") + + +macro(find_qt) + set(_QCOMP) + foreach(_v ${_QT_VERSIONS_}) + set(_NEED${_v} 0) + set(LOCAL_FOUND${_v} 0) + set(MOC_INC_Qt${_v}) + set(Qt${_v}_INCLUDES) + set(Qt${_v}_LIBRARIES) + set(Qt${_v}_ROOT) + set(Qt${_v}_BIN) + set(Qt${_v}_PLUGINS_DIR) + set(Qt${_v}_LANG_DIR) + endforeach() + set(_NEED_SOME 0) + set(_QUIET) + foreach(_i ${ARGN}) + set(_FOUND_NEED 0) + foreach(_v ${_QT_VERSIONS_}) + if ("x${_i}" STREQUAL "xQt${_v}") + set(_NEED${_v} 1) + set(_NEED_SOME 1) + set(_FOUND_NEED 1) + endif() + if ("x${_i}" STREQUAL "xQUIET") + set(_QUIET QUIET) + endif() + endforeach() + if (NOT _FOUND_NEED) + list(APPEND _QCOMP "${_i}") + endif() + endforeach() + if (NOT _NEED_SOME) + foreach(_v ${_QT_VERSIONS_}) + set(_NEED${_v} 1) + endforeach() + endif() + list(REMOVE_DUPLICATES _QCOMP) + if (_NEED4) + find_package(Qt4 ${_QUIET}) + if (Qt4_FOUND) + set(LOCAL_FOUND4 1) + get_filename_component(Qt4_BIN ${QT_QMAKE_EXECUTABLE} PATH) + set(Qt4_INCLUDES ${QT_INCLUDES}) + foreach(m ${_QCOMP}) + string(TOUPPER "${m}" _um) + #message("${QT_QT${_um}_FOUND}") + if (${QT_QT${_um}_FOUND}) + list(APPEND Qt4_LIBRARIES ${QT_QT${_um}_LIBRARY}) + endif() + endforeach() + set(Qt4_PLUGINS_DIR ${QT_PLUGINS_DIR}) + set(Qt4_LANG_DIR ${Qt4_BIN}/../translations) + set(Qt4_ROOT "${Qt4_BIN}/../") + endif() + endif() + if (_NEED5) + #set(_MSG 1) + #if (Qt5_FOUND) + # set(_MSG 0) + #endif() + find_package(Qt5 COMPONENTS Core LinguistTools UiPlugin Widgets ${_QCOMP} ${_QUIET}) + if (DEFINED ANDROID_PLATFORM) + set(CMAKE_SHARED_MODULE_SUFFIX_CXX ".so") + set(CMAKE_SHARED_LIBRARY_SUFFIX_CXX ".so") + set(CMAKE_SHARED_MODULE_SUFFIX_C ".so") + set(CMAKE_SHARED_LIBRARY_SUFFIX_C ".so") + endif() + if (Qt5_FOUND) + set(LOCAL_FOUND5 1) + set(_Qt5Modules) + foreach(m ${_QCOMP}) + if (${Qt5${m}_FOUND}) + set(__lib ${Qt5${m}_LIBRARIES}) + if (DEFINED ANDROID_PLATFORM) + if (m IN_LIST __qt_bug_modules) + get_target_property(__lib Qt5::${m} LOCATION) + endif() + endif() + list(APPEND _Qt5Modules ${m}) + list(APPEND Qt5_INCLUDES ${Qt5${m}_INCLUDE_DIRS}) + list(APPEND Qt5_LIBRARIES ${__lib}) + endif() + endforeach() + #get_property(_up_dir TARGET Qt5::UiPlugin PROPERTY INTERFACE_INCLUDE_DIRECTORIES) + #message("${_up_dir}") + #if (NOT "x${_up_dir}" STREQUAL "x") + # list(APPEND Qt5_INCLUDES ${_up_dir}) + #endif() + get_target_property(_Qt5_qmake Qt5::qmake LOCATION) + get_filename_component(Qt5_BIN ${_Qt5_qmake} PATH) + foreach(_p ${Qt5Gui_PLUGINS}) + get_target_property(_l ${_p} LOCATION) + get_filename_component(_l ${_l} DIRECTORY) + string(FIND "${_l}" "/" _ind REVERSE) + string(SUBSTRING "${_l}" 0 ${_ind} _l) + set(Qt5_PLUGINS_DIR ${_l}) + #message("Qt5: plugins dir: ${Qt5_PLUGINS_DIR}") + break() + endforeach() + string(FIND "${Qt5_BIN}" "/" _ind REVERSE) + string(SUBSTRING "${Qt5_BIN}" 0 ${_ind} Qt5_ROOT) + if ("x${Qt5_PLUGINS_DIR}" STREQUAL "x") + set(Qt5_PLUGINS_DIR "${Qt5_ROOT}/plugins") + endif() + if (APPLE) + list(APPEND MOC_INC_Qt5 "-F${Qt5_ROOT}/lib") + endif() + set(Qt5_LANG_DIR ${Qt5_BIN}/../translations) + if (NOT _QT5_MSG) + message(STATUS "Found Qt5: ${_Qt5_qmake} (version \"${Qt5_VERSION}\")") + set(_QT5_MSG 1 CACHE BOOL "msg_qt5" FORCE) + #message(STATUS "Found Qt5 modules: ${_Qt5Modules}") + endif() + endif() + endif() + foreach(_v ${_QT_VERSIONS_}) + if (LOCAL_FOUND${_v}) + foreach(_p ${Qt${_v}_INCLUDES}) + list(APPEND MOC_INC_Qt${_v} "-I${_p}") + #message("${_p}") + endforeach() + endif() + #message("${MOC_INC_Qt${_v}}") + endforeach() + +endmacro() + + +macro(qt_sources OUT) + set(${OUT}) + set(_DIR "") + set(_IS_DIR 0) + set(_NO_DEFAULT 0) + set(_DEFAULT) + set(_REGEXP) + set(_REGEXP_WD) + foreach(_i ${ARGN}) + if (_IS_DIR) + set(_DIR "${_i}") + set(_IS_DIR 0) + elseif ("x${_i}" STREQUAL "xDIR") + set(_IS_DIR 1) + elseif ("x${_i}" STREQUAL "xNO_DEFAULT") + set(_NO_DEFAULT 1) + else() + list(APPEND _REGEXP ${_i}) + endif() + endforeach() + if (NOT "x${_DIR}" STREQUAL "x") + #file(TO_CMAKE_PATH "${_DIR}//" _DIR) + string(REPLACE "\\" "/" _DIR "${_DIR}/") + string(REPLACE "//" "/" _DIR "${_DIR}") + endif() + foreach(_i ${_REGEXP}) + list(APPEND _REGEXP_WD "${_DIR}${_i}") + endforeach() + if (NOT _NO_DEFAULT) + set(_DEFAULT "${_DIR}*.h" "${_DIR}*.hpp" "${_DIR}*.c" "${_DIR}*.cpp" "${_DIR}*.ui" "${_DIR}*.qrc" "${_DIR}*.rc" "${_DIR}*.ts" "${_DIR}lang/*.ts") + endif() + #message("${_DEFAULT}, ${_REGEXP_WD}") + file(GLOB ${OUT} ${_DEFAULT} ${_REGEXP_WD}) +endmacro() + + +macro(qt_wrap) + set(HDR_VAR) + set(CPP_VAR) + set(QM_VAR) + set(_HDR_ARG 0) + set(_CPP_ARG 0) + set(_QM_ARG 0) + set(WAS_HDR_ARG 0) + set(WAS_CPP_ARG 0) + set(WAS_QM_ARG 0) + set(FILE_LIST) + foreach(_i ${ARGN}) + if (_HDR_ARG) + set(HDR_VAR ${_i}) + set(WAS_HDR_ARG 1) + set(_HDR_ARG 0) + elseif (_CPP_ARG) + set(CPP_VAR ${_i}) + set(WAS_CPP_ARG 1) + set(_CPP_ARG 0) + elseif (_QM_ARG) + set(QM_VAR ${_i}) + set(WAS_QM_ARG 1) + set(_QM_ARG 0) + elseif ("x${_i}" STREQUAL "xHDRS") + set(_HDR_ARG 1) + elseif ("x${_i}" STREQUAL "xCPPS") + set(_CPP_ARG 1) + elseif ("x${_i}" STREQUAL "xQMS") + set(_QM_ARG 1) + else() + list(APPEND FILE_LIST "${_i}") + endif() + endforeach() + foreach(_v ${_QT_VERSIONS_}) + set(CPP${_v}_VAR) + set(QM${_v}_VAR) + if (LOCAL_FOUND${_v}) + if (WAS_CPP_ARG) + set(CPP${_v}_VAR ${CPP_VAR}_Qt${_v}) + endif() + if (WAS_QM_ARG) + set(QM${_v}_VAR ${QM_VAR}_Qt${_v}) + endif() + endif() + endforeach() + #message("found 4: ${LOCAL_FOUND4}, 5: ${LOCAL_FOUND5}") + #message("has HRDS: ${WAS_HDR_ARG}: ${HDR_VAR}") + #message("has CPPS4: ${WAS_CPP_ARG}: ${CPP4_VAR}") + #message("has CPPS5: ${WAS_CPP_ARG}: ${CPP5_VAR}") + #message("files: ${FILE_LIST}") + set(H_LIST) + set(CPP_LIST) + set(UI_LIST) + set(RES_LIST) + set(RC_LIST) + set(TS_LIST) + foreach(_i ${FILE_LIST}) + get_filename_component(_EXT "${_i}" EXT) + #message("${_EXT}") + if (NOT ("x${_EXT}" STREQUAL "x")) + if (("x${_EXT}" STREQUAL "x.h") OR ("x${_EXT}" STREQUAL "x.hpp")) + list(APPEND H_LIST "${_i}") + #message("header") + endif() + if (("x${_EXT}" STREQUAL "x.c") OR ("x${_EXT}" STREQUAL "x.cpp") OR ("x${_EXT}" STREQUAL "x.cxx")) + list(APPEND CPP_LIST "${_i}") + #message("source") + endif() + if ("x${_EXT}" STREQUAL "x.ui") + list(APPEND UI_LIST "${_i}") + endif() + if ("x${_EXT}" STREQUAL "x.qrc") + list(APPEND RES_LIST "${_i}") + endif() + if ("x${_EXT}" STREQUAL "x.rc") + list(APPEND RC_LIST "${_i}") + endif() + if ("x${_EXT}" STREQUAL "x.ts") + list(APPEND TS_LIST "${_i}") + endif() + endif() + endforeach() + if (WAS_HDR_ARG) + set(${HDR_VAR}) + list(APPEND ${HDR_VAR} ${H_LIST}) + endif() + set(SRC_CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) + foreach(_v ${_QT_VERSIONS_}) + if (LOCAL_FOUND${_v} AND WAS_CPP_ARG) + set(CMAKE_CURRENT_BINARY_DIR ${SRC_CMAKE_CURRENT_BINARY_DIR}/qt${_v}) + set(${CPP${_v}_VAR}) + if (WAS_QM_ARG) + set(${QM${_v}_VAR}) + endif() + set(MOCS${_v}) + set(CUIS${_v}) + set(CRES${_v}) + if (${_v} EQUAL 4) + qt4_wrap_cpp(MOCS${_v} ${H_LIST} OPTIONS -nw ${MOC_INC_Qt4}) + qt4_wrap_ui(CUIS${_v} ${UI_LIST}) + qt4_add_resources(CRES${_v} ${RES_LIST}) + if (WAS_QM_ARG) + set(${QM${_v}_VAR} "") + qt4_add_translation(${QM${_v}_VAR} ${TS_LIST}) + endif() + elseif (${_v} EQUAL 5) + qt5_wrap_cpp(MOCS${_v} ${H_LIST} OPTIONS -nw ${MOC_INC_Qt5}) + qt5_wrap_ui(CUIS${_v} ${UI_LIST}) + qt5_add_resources(CRES${_v} ${RES_LIST}) + if (WAS_QM_ARG) + set(${QM${_v}_VAR} "") + qt5_add_translation(${QM${_v}_VAR} ${TS_LIST}) + endif() + else() + # Qt6 ... + endif() + #message("${${QM${_v}_VAR}}") + list(APPEND ${CPP${_v}_VAR} ${CPP_LIST}) + list(APPEND ${CPP${_v}_VAR} ${RC_LIST}) + list(APPEND ${CPP${_v}_VAR} ${MOCS${_v}}) + list(APPEND ${CPP${_v}_VAR} ${CUIS${_v}}) + list(APPEND ${CPP${_v}_VAR} ${CRES${_v}}) + if (WAS_QM_ARG) + list(APPEND ${CPP${_v}_VAR} ${${QM${_v}_VAR}}) + endif() + #message("${${QM${_v}_VAR}}") + endif() + endforeach() + set(CMAKE_CURRENT_BINARY_DIR ${SRC_CMAKE_CURRENT_BINARY_DIR}) +endmacro() + + +macro(_qt_split_add_args _P _A) + set(${_P}) + set(${_A}) + foreach(_i ${ARGN}) + if (NOT ("x${${_i}_Qt${_v}}" STREQUAL "x")) + list(APPEND ${_A} ${${_i}_Qt${_v}}) + elseif (("x${_i}" STREQUAL "xWIN32") OR + ("x${_i}" STREQUAL "xMACOSX_BUNDLE") OR + ("x${_i}" STREQUAL "xSTATIC") OR + ("x${_i}" STREQUAL "xSHARED") OR + ("x${_i}" STREQUAL "xMODULE") OR + ("x${_i}" STREQUAL "xEXCLUDE_FROM_ALL")) + list(APPEND ${_P} ${_i}) + elseif ("x${${_i}}" STREQUAL "x") + list(APPEND ${_A} ${_i}) + else() + list(APPEND ${_A} ${${_i}}) + endif() + endforeach() +endmacro() + + +macro(__qt_set_defines _NAME _T) + target_compile_definitions(${_T} PRIVATE "__TARGET_NAME__=\"${_NAME}\"") + target_compile_definitions(${_T} PRIVATE "__TARGET_LABEL__=\"${${_NAME}_LABEL}\"") + target_compile_definitions(${_T} PRIVATE "__TARGET_COMPANY__=\"${${_NAME}_COMPANY}\"") + target_compile_definitions(${_T} PRIVATE "__TARGET_VERSION__=\"${${_NAME}_VERSION}\"") +endmacro() + + +macro(qt_add_executable _NAME) + foreach(_v ${_QT_VERSIONS_}) + if (LOCAL_FOUND${_v}) + _qt_split_add_args(_PREF _ARGS ${ARGN}) + if(APPLE) + set(_PREV_CIND "${CMAKE_INSTALL_NAME_DIR}") + set(CMAKE_INSTALL_NAME_DIR "@rpath") + else() + if(NOT WIN32) + set(CMAKE_INSTALL_RPATH "\$ORIGIN;\$ORIGIN/lib") + endif() + endif() + set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}}) + add_executable(${_TARGET} ${_PREF} ${_ARGS}) + set(_${_NAME}_is_qt 1) + target_include_directories(${_TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/qt${_v} ${Qt${_v}_INCLUDES}) + __qt_set_defines(${_NAME} ${_TARGET}) + + if(APPLE) + set(CMAKE_INSTALL_NAME_DIR "${_PREV_CIND}") + endif() + # # Apple crosscompiling rpath patch + # if (APPLE AND CMAKE_CROSSCOMPILING AND CMAKE_MACOSX_RPATH) + # foreach(_RP ${CMAKE_INSTALL_RPATH}) + # add_custom_command(TARGET ${_TARGET} POST_BUILD + # COMMAND "${CMAKE_INSTALL_NAME_TOOL}" + # "-add_rpath" "${_RP}" + # "$/$" + # COMMENT "Add to ${_TARGET} rpath \"${_RP}\"") + # endforeach() + # endif() + + #list(APPEND _ALL_TARGETS "${_TARGET}") + #set(_ALL_TARGETS ${_ALL_TARGETS} PARENT_SCOPE) + endif() + endforeach() +endmacro() + + +macro(qt_add_library _NAME) + foreach(_v ${_QT_VERSIONS_}) + if (LOCAL_FOUND${_v}) + _qt_split_add_args(_PREF _ARGS ${ARGN}) + if(APPLE) + set(_PREV_CIND "${CMAKE_INSTALL_NAME_DIR}") + set(CMAKE_INSTALL_NAME_DIR "@rpath") + else() + if(NOT WIN32) + set(CMAKE_INSTALL_RPATH "\$ORIGIN;\$ORIGIN/lib") + endif() + endif() + set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}}) + add_library(${_TARGET} ${_PREF} ${_ARGS}) + set(_${_NAME}_is_qt 1) + target_include_directories(${_TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/qt${_v} ${Qt${_v}_INCLUDES}) + __qt_set_defines(${_NAME} ${_TARGET}) + #message("add lib: \"${_TARGET}\"") + + if(APPLE) + set(CMAKE_INSTALL_NAME_DIR "${_PREV_CIND}") + endif() + # # Apple crosscompiling rpath patch + # if (APPLE AND CMAKE_CROSSCOMPILING AND CMAKE_MACOSX_RPATH) + # foreach(_RP ${CMAKE_INSTALL_RPATH}) + # add_custom_command(TARGET ${_TARGET} POST_BUILD + # COMMAND "${CMAKE_INSTALL_NAME_TOOL}" + # "-add_rpath" "${_RP}" + # "$/$" + # COMMENT "Add to ${_TARGET} rpath \"${_RP}\"") + # endforeach() + # endif() + + list(APPEND _ALL_TARGETS "${_TARGET}") + set(_ALL_TARGETS ${_ALL_TARGETS} PARENT_SCOPE) + endif() + endforeach() +endmacro() + + +macro(_qt_multitarget_suffix_ _OUT _IN _v) + string(REPLACE ":" "_" _in_str "${_IN}") + if (NOT "x${MULTILIB_${_in_str}_SUFFIX_Qt${_v}}" STREQUAL "x") + set(${_OUT} "${MULTILIB_${_in_str}_SUFFIX_Qt${_v}}") + else() + set(${_OUT} "${MULTILIB_SUFFIX_Qt${_v}}") + endif() +endmacro() + + +macro(qt_target_link_libraries _NAME) + foreach(_v ${_QT_VERSIONS_}) + if (LOCAL_FOUND${_v}) + set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}}) + set(_ARGS) + foreach(_i ${ARGN}) + set(_ind -1) + list(FIND QT_MULTILIB_LIST "${_i}" _ind) + if (_ind GREATER -1) + _qt_multitarget_suffix_(_TS ${_i} ${_v}) + #message(STATUS "${_i} in MULTILIB_LIST, suffix = ${_TS}") + list(APPEND _ARGS ${_i}${_TS}) + else() + list(APPEND _ARGS ${_i}) + endif() + endforeach() + target_link_libraries(${_TARGET} ${Qt${_v}_LIBRARIES} ${_ARGS}) + #message("link ${_TARGET}: ${Qt${_v}_LIBRARIES} ${_ARGS}") + endif() + endforeach() +endmacro() + + +macro(qt_target_compile_definitions _NAME) + foreach(_v ${_QT_VERSIONS_}) + if (LOCAL_FOUND${_v}) + set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}}) + target_compile_definitions(${_TARGET} ${ARGN}) + endif() + endforeach() +endmacro() + + +macro(qt_target_include_directories _NAME) + foreach(_v ${_QT_VERSIONS_}) + if (LOCAL_FOUND${_v}) + set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}}) + target_include_directories(${_TARGET} ${ARGN}) + endif() + endforeach() +endmacro() + + +macro(qt_install) + set(_prev_inst) + set(__add_args) + #message("command: ${ARGN}") + foreach(_v ${_QT_VERSIONS_}) + if (LOCAL_FOUND${_v}) + set(_INST_LIST) + set(_IS_TARGET 0) + set(_IS_FILES 0) + set(_IS_DEST 0) + set(_IS_LANG 0) + set(_INVALID 0) + foreach(_i ${ARGN}) + if ("x${_i}" STREQUAL "xQtLang") + set(_IS_LANG 1) + endif() + endforeach() + foreach(_i ${ARGN}) + if (_IS_TARGET) + set(_IS_TARGET 0) + set(__target ${_i}) + if (_${_i}_is_qt) + set(__target ${_i}${TARGET_SUFFIX_Qt${_v}}) + endif() + if (DEFINED ANDROID_PLATFORM) + get_target_property(_TT ${__target} TYPE) + if ("x${_TT}" STREQUAL "xEXECUTABLE") + list(APPEND __add_args EXCLUDE_FROM_ALL) + endif() + endif() + list(APPEND _INST_LIST ${__target}) + elseif (_IS_FILES) + set(_IS_FILES 0) + if (_IS_LANG) + if (("x${${_i}_Qt${_v}}" STREQUAL "x") OR ("x${_i}" STREQUAL "xDESTINATION")) + set(_INVALID 1) + else() + list(APPEND _INST_LIST ${${_i}_Qt${_v}}) + endif() + else() + list(APPEND _INST_LIST ${_i}) + endif() + else() + if (_IS_DEST) + set(_IS_DEST 0) + if ("x${_i}" STREQUAL "xQtBin") + list(APPEND _INST_LIST "${Qt${_v}_BIN}") + elseif ("x${_i}" STREQUAL "xQtLang") + list(APPEND _INST_LIST "${Qt${_v}_LANG_DIR}") + else() + set(_ind -1) + string(FIND "${_i}" "QtPlugins" _ind) + if (_ind GREATER -1) + string(REPLACE "QtPlugins" "${Qt${_v}_PLUGINS_DIR}" _o "${_i}") + list(APPEND _INST_LIST "${_o}") + else() + string(REPLACE "\\" "/" _o "${_i}") + list(APPEND _INST_LIST ${_o}) + endif() + endif() + else() + set(_ii ${_i}) + if ("x${_i}" STREQUAL "xTARGETS") + set(_IS_TARGET 1) + elseif ("x${_i}" STREQUAL "xFILES") + set(_IS_FILES 1) + elseif ("x${_i}" STREQUAL "xDESTINATION") + set(_IS_DEST 1) + elseif ("x${_i}" STREQUAL "xLANG") + set(_IS_FILES 1) + set(_IS_LANG 1) + set(_ii "FILES") + endif() + list(APPEND _INST_LIST ${_ii}) + endif() + endif() + endforeach() + if (NOT _INVALID) + if (NOT ("x${_prev_inst}" STREQUAL "x${_INST_LIST}")) + #message("install: ${_INST_LIST}") + install(${_INST_LIST} ${__add_args}) + set(_prev_inst "${_INST_LIST}") + endif() + endif() + endif() + endforeach() +endmacro() + + +macro(qt_install_lang _NAME) + set(_prev_inst) + #message("command: ${ARGN}") + set(_PATHS) + set(_DEST) + if(CMAKE_CROSSCOMPILING) + list(APPEND _PATHS "${CMAKE_PREFIX_PATH}/lang") + endif() + set(_cur_arg) + set(__args "DESTINATION;PATHS") + foreach(_i ${ARGN}) + if (_i IN_LIST __args) + set(_cur_arg "${_i}") + elseif("${_cur_arg}" STREQUAL "DESTINATION") + set(_DEST "${_i}") + elseif("${_cur_arg}" STREQUAL "PATHS") + list(APPEND _PATHS "${_i}") + endif() + endforeach() + foreach(_v ${_QT_VERSIONS_}) + if (LOCAL_FOUND${_v}) + set(_target) + if (_${_NAME}_is_qt) + set(_target ${_NAME}${TARGET_SUFFIX_Qt${_v}}) + endif() + get_target_property(_LL ${_target} LINK_LIBRARIES) + foreach (_L ${_LL}) + get_filename_component(_libname "${_L}" NAME_WE) + #message("depend on ${_libname}") + if ("${_libname}" MATCHES "Qt${_v}::.*") + string(SUBSTRING "${_libname}" 5 -1 _libname) + string(TOLOWER "${_libname}" _libname) + #message("qt lib \"${_libname}\"") + list(APPEND _qt_libs qt${_libname}) + else() + if ("${_libname}" MATCHES "lib.*") + string(LENGTH ${_libname} _sl) + math(EXPR _sl ${_sl}-3) + string(SUBSTRING ${_libname} 3 ${_sl} _libname) + endif() + if ("${_libname}" MATCHES "qad_.*${_v}") + string(LENGTH ${_libname} _sl) + math(EXPR _sl ${_sl}-1) + string(SUBSTRING ${_libname} 0 ${_sl} _libname) + #message("qad lib \"${_libname}\"") + list(APPEND _qt_libs ${_libname}) + endif() + endif() + endforeach() + if (NOT "x${_qt_libs}" STREQUAL "x") + list(APPEND _qt_libs "qtbase") + foreach (_i ${${PROJECT_NAME}_LANG}) + foreach (_l ${_qt_libs}) + unset(_qm_path CACHE) + find_file(_qm_path "${_l}_${_i}.qm" PATHS "${Qt${_v}_LANG_DIR}" ${_PATHS} NO_DEFAULT_PATH) + if (EXISTS "${_qm_path}") + install(FILES ${_qm_path} DESTINATION "${_DEST}") + #message("qm = \"${_qm_path}\"") + endif() + endforeach() + endforeach() + endif() + endif() + endforeach() +endmacro() + + +macro(qt_get_target _NAME _OUT) + set(${_OUT}) + set(_ver) + foreach(_i ${ARGN}) + foreach(_v ${_QT_VERSIONS_}) + if ("x${_i}" STREQUAL "xQt${_v}") + set(_ver ${_v}) + break() + endif() + endforeach() + if (NOT "x${_ver}" STREQUAL "x") + break() + endif() + endforeach() + foreach(_v ${_QT_VERSIONS_}) + if (LOCAL_FOUND${_v} AND (("x${_ver}" STREQUAL "x") OR ((NOT "x${_ver}" STREQUAL "x") AND ("x${_ver}" STREQUAL "x${_v}")))) + set(${_OUT} ${_NAME}${TARGET_SUFFIX_Qt${_v}}) + endif() + endforeach() +endmacro() + + +macro(qt_get_targets _NAME _OUT) + set(${_OUT}) + foreach(_v ${_QT_VERSIONS_}) + if (LOCAL_FOUND${_v}) + list(APPEND ${_OUT} ${_NAME}${TARGET_SUFFIX_Qt${_v}}) + endif() + endforeach() +endmacro() + + +macro(qt_generate_export_header _NAME) + qt_get_target(${_NAME} _some_target) + qt_get_target(${_NAME} _targets) + foreach(_t ${_targets}) + set_target_properties(${_t} PROPERTIES DEFINE_SYMBOL ${_NAME}_EXPORTS) + endforeach() + set_target_properties(${_some_target} PROPERTIES DEFINE_SYMBOL ${_NAME}_EXPORTS) + generate_export_header(${_some_target} BASE_NAME "${_NAME}" ${ARGN}) +endmacro() diff --git a/cmake_android.bat b/cmake_android.bat deleted file mode 100644 index 94d9290..0000000 --- a/cmake_android.bat +++ /dev/null @@ -1,50 +0,0 @@ -@echo off -rem Please add to environment ANDROID_QT5_DIR (path to Qt directory) and ANDROID_NDK_HOME (path to android ndk directory) -rem Execute with Android API version and arch e. g. : #cmake_android.bat 24 arm ../libs -rem Arches: arm, arm64, x86, x86_64 -set _usage_=0 -if [%~1]==[] set _usage_=1 -if [%~2]==[] set _usage_=1 -if [%~3]==[] set _usage_=1 -if %_usage_%==1 ( - echo Usage: cmake_android.bat ^ ^ ^ - echo ^ ^ ^ - number of API ^(e.g. 19^) - echo ^ ^ ^ - architecture ^(arm, arm64, x86, x86_64^) - echo ^ ^ ^ - path to sources - echo. - echo You also have to set next env variables^: - echo ^ ^ ANDROID_QT5_DIR - path to Qt dir, contains subdirs for arch - echo ^ ^ ANDROID_NDK_HOME - path to android ndk directory - exit /b -) -set QARCH= -set AARCH= -set _PLATFORM_=%~1 -if %~2==arm ( - set QARCH=armv7 - set AARCH=armeabi-v7a -) -if %~2==arm64 ( - set QARCH=arm64_v8a - set AARCH=arm64-v8a - if /i %_PLATFORM_% LSS 21 set _PLATFORM_=21 -) -if %~2==x86 ( - set QARCH=x86 - set AARCH=x86 -) -if %~2==x86_64 ( - set QARCH=x86_64 - set AARCH=x86_64 - if /i %_PLATFORM_% LSS 21 set _PLATFORM_=21 -) -rem set Qt5_ROOT=%ANDROID_QT5_DIR%\android_%QARCH%\lib\cmake -set Qt5_ROOT=%ANDROID_QT5_DIR%\lib\cmake -rem set Qt5_DIR=%Qt5_ROOT%\Qt5 -if NOT [%QARCH%]==[] ( - @echo on - cmake_mgw -Wno-dev -DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK_HOME%\build\cmake\android.toolchain.cmake -DANDROID_STL=c++_shared -DANDROID_PLATFORM=android-%_PLATFORM_% -DANDROID_ABI=%AARCH% -DICU=0 -DQt4=0 -DQt5=1 -DQGLVIEW=0 -DQGLENGINE=0 -DQt5_DIR=%Qt5_ROOT%\Qt5 -DQt5LinguistTools_DIR=%Qt5_ROOT%\Qt5LinguistTools -DQt5UiPlugin_DIR=%Qt5_ROOT%\Qt5UiPlugin -DQt5UiTools_DIR=%Qt5_ROOT%\Qt5UiTools -DQt5Widgets_DIR=%Qt5_ROOT%\Qt5Widgets -DQt5Core_DIR=%Qt5_ROOT%\Qt5Core -DQt5Gui_DIR=%Qt5_ROOT%\Qt5Gui -DQt5Sql_DIR=%Qt5_ROOT%\Qt5Sql -DQt5OpenGL_DIR=%Qt5_ROOT%\Qt5OpenGL -DQt5PrintSupport_DIR=%Qt5_ROOT%\Qt5PrintSupport -DQt5Script_DIR=%Qt5_ROOT%\Qt5Script -DQt5Positioning_DIR=%Qt5_ROOT%\Qt5Positioning -DQt5Network_DIR=%Qt5_ROOT%\Qt5Network -DQt5Qml_DIR=%Qt5_ROOT%\Qt5Qml -DQt5Quick_DIR=%Qt5_ROOT%\Qt5Quick -DQt5QuickWidgets_DIR=%Qt5_ROOT%\Qt5QuickWidgets -DQt5QmlModels_DIR=%Qt5_ROOT%\Qt5QmlModels -DQt5AndroidExtras_DIR=%Qt5_ROOT%\Qt5AndroidExtras %~3 %~4 %~5 %~6 -) else ( - @echo on - cmake_mgw -Wno-dev -DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK_HOME%\build\cmake\android.toolchain.cmake -DANDROID_STL=c++_shared -DANDROID_PLATFORM=android-%_PLATFORM_% -DANDROID_ABI=%AARCH% -DICU=0 -DQt4=0 -DQt5=0 -DQGLVIEW=0 %~3 %~4 %~5 %~6 -) diff --git a/cmake_android.sh b/cmake_android.sh deleted file mode 100755 index 9b7e609..0000000 --- a/cmake_android.sh +++ /dev/null @@ -1,3 +0,0 @@ -export SDK_DIR=/usr/lib/android-sdk -export PREFIX=/soft/android -rm -rf * && cmake -DCMAKE_TOOLCHAIN_FILE=${SDK_DIR}/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-21 -DQt4=0 -DQt5=1 -DQt5_DIR=${PREFIX}/qt/lib/cmake/Qt5 ../libs diff --git a/docker/android-libs/Dockerfile b/docker/android-libs/Dockerfile deleted file mode 100644 index e94bc3f..0000000 --- a/docker/android-libs/Dockerfile +++ /dev/null @@ -1,43 +0,0 @@ -ARG DOCKER_PREFIX=wapmobil/ -FROM ${DOCKER_PREFIX}android - -ARG LIBS_BUILD_NUMBER=9999 -ARG JOBS_COUNT=4 -ENV PATH=/opt/cmake/bin:$PATH -ENV ANDROID_HOME=/usr/lib/android-sdk -ENV ANDROID_NDK_HOME=${ANDROID_HOME}/ndk-bundle -ENV ANDROID_TOOLCHAIN=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake -ENV NDK_PLATFORM="android-21" - -WORKDIR /soft -RUN git clone -b release --single-branch --depth 1 --recursive https://git.shs.tools/SHS/libs.git - -WORKDIR /soft/libs_build_host -RUN cmake -DICU=0 -DCROSSTOOLS=1 -DBUILD_NUMBER=${LIBS_BUILD_NUMBER} ../libs \ - && make install -j${JOBS_COUNT} \ - && rm -rf * \ - && ldconfig - -WORKDIR /soft/libs_build_anroid -ENV _ANDROID_TOOLCHAIN=/usr/lib/android-sdk/ndk-bundle/build/cmake/android.toolchain.cmake - -ENV _CUR_ABI=armeabi-v7a -RUN cmake -DCMAKE_INSTALL_PREFIX=/soft/android/${_CUR_ABI} -DICU=0 -DLIB=0 -DQGLENGINE=0 -DQGLVIEW=0 -DBUILD_NUMBER=${LIBS_BUILD_NUMBER} -DCMAKE_TOOLCHAIN_FILE=${_ANDROID_TOOLCHAIN} -DQt5_DIR=/soft/android/qt/lib/cmake/Qt5 -DANDROID_PLATFORM=${NDK_PLATFORM} -DANDROID_ABI=${_CUR_ABI} ../libs/ \ - && make install -j${JOBS_COUNT} && rm -rf * - -ENV _CUR_ABI=arm64-v8a -WORKDIR /soft/libs_build_android_${_CUR_ABI} -RUN cmake -DCMAKE_INSTALL_PREFIX=/soft/android/${_CUR_ABI} -DICU=0 -DLIB=0 -DQGLENGINE=0 -DQGLVIEW=0 -DBUILD_NUMBER=${LIBS_BUILD_NUMBER} -DCMAKE_TOOLCHAIN_FILE=${_ANDROID_TOOLCHAIN} -DQt5_DIR=/soft/android/qt/lib/cmake/Qt5 -DANDROID_PLATFORM=${NDK_PLATFORM} -DANDROID_ABI=${_CUR_ABI} ../libs/ \ - && make install -j${JOBS_COUNT} && rm -rf * - -ENV _CUR_ABI=x86 -WORKDIR /soft/libs_build_android_${_CUR_ABI} -RUN cmake -DCMAKE_INSTALL_PREFIX=/soft/android/${_CUR_ABI} -DICU=0 -DLIB=0 -DQGLENGINE=0 -DQGLVIEW=0 -DBUILD_NUMBER=${LIBS_BUILD_NUMBER} -DCMAKE_TOOLCHAIN_FILE=${_ANDROID_TOOLCHAIN} -DQt5_DIR=/soft/android/qt/lib/cmake/Qt5 -DANDROID_PLATFORM=${NDK_PLATFORM} -DANDROID_ABI=${_CUR_ABI} ../libs/ \ - && make install -j${JOBS_COUNT} && rm -rf * - -ENV _CUR_ABI=x86_64 -WORKDIR /soft/libs_build_android_${_CUR_ABI} -RUN cmake -DCMAKE_INSTALL_PREFIX=/soft/android/${_CUR_ABI} -DICU=0 -DLIB=0 -DQGLENGINE=0 -DQGLVIEW=0 -DBUILD_NUMBER=${LIBS_BUILD_NUMBER} -DCMAKE_TOOLCHAIN_FILE=${_ANDROID_TOOLCHAIN} -DQt5_DIR=/soft/android/qt/lib/cmake/Qt5 -DANDROID_PLATFORM=${NDK_PLATFORM} -DANDROID_ABI=${_CUR_ABI} ../libs/ \ - && make install -j${JOBS_COUNT} && rm -rf * - -WORKDIR /soft/src diff --git a/docker/debian-libs/Dockerfile b/docker/debian-libs/Dockerfile deleted file mode 100644 index 0a85c7f..0000000 --- a/docker/debian-libs/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -ARG DOCKER_PREFIX=wapmobil/ -FROM ${DOCKER_PREFIX}debian - -ARG LIBS_BUILD_NUMBER=9999 -ARG JOBS_COUNT=4 -ENV PATH=/opt/cmake/bin:$PATH - -WORKDIR /soft -RUN git clone -b release --single-branch --depth 1 --recursive https://git.shs.tools/SHS/libs.git - -WORKDIR /soft/libs_build_debian -RUN cmake -DICU=0 -DLIB=1 -DQGLENGINE=1 -DQGLVIEW=1 -DBUILD_NUMBER=${LIBS_BUILD_NUMBER} ../libs \ - && make install -j${JOBS_COUNT} \ - && rm -rf * \ - && ldconfig - -WORKDIR /soft/src diff --git a/docker/osx-libs/Dockerfile b/docker/osx-libs/Dockerfile deleted file mode 100644 index 5a496e4..0000000 --- a/docker/osx-libs/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -ARG DOCKER_PREFIX=wapmobil/ -FROM ${DOCKER_PREFIX}osx - -ARG LIBS_BUILD_NUMBER=9999 -ARG JOBS_COUNT=4 -ENV PATH=/soft/osxcross/target/bin:/opt/cmake/bin:$PATH - -WORKDIR /soft -RUN git clone -b release --single-branch --depth 1 --recursive https://git.shs.tools/SHS/libs.git - -WORKDIR /soft/libs_build_host -RUN cmake -DICU=0 -DCROSSTOOLS=1 -DBUILD_NUMBER=${LIBS_BUILD_NUMBER} ../libs \ - && make install -j${JOBS_COUNT} \ - && rm -rf * \ - && ldconfig - -WORKDIR /soft/libs_build_osx -RUN cmake -DCMAKE_INSTALL_PREFIX=/soft/osx -DICU=0 -DLIB=0 -DQGLENGINE=1 -DQGLVIEW=1 -DBUILD_NUMBER=${LIBS_BUILD_NUMBER} -DCMAKE_TOOLCHAIN_FILE=/soft/toolchain-Darwin.cmake ../libs/ \ - && make install -j${JOBS_COUNT} && rm -rf * - -WORKDIR /soft/src diff --git a/docker/pi-libs/Dockerfile b/docker/pi-libs/Dockerfile deleted file mode 100644 index 666e20c..0000000 --- a/docker/pi-libs/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -ARG DOCKER_PREFIX=wapmobil/ -FROM ${DOCKER_PREFIX}pi - -ARG LIBS_BUILD_NUMBER=9999 -ARG JOBS_COUNT=4 -ENV PATH=/opt/cmake/bin:$PATH - -WORKDIR /soft -RUN git clone -b release --single-branch --depth 1 --recursive https://git.shs.tools/SHS/libs.git - -WORKDIR /soft/libs_build_host -RUN cmake -DICU=0 -DCROSSTOOLS=1 -DBUILD_NUMBER=${LIBS_BUILD_NUMBER} ../libs \ - && make install -j${JOBS_COUNT} \ - && rm -rf * \ - && ldconfig - -WORKDIR /soft/libs_build_pi -RUN cmake -DCMAKE_INSTALL_PREFIX=/soft/pi/usr -DICU=0 -DLIB=0 -DQGLENGINE=0 -DQGLVIEW=0 -DBUILD_NUMBER=${LIBS_BUILD_NUMBER} -DCMAKE_TOOLCHAIN_FILE=/soft/toolchain-RPi.cmake ../libs/ \ - && make install -j${JOBS_COUNT} && rm -rf * - -WORKDIR /soft/src diff --git a/docker/windows-libs/Dockerfile b/docker/windows-libs/Dockerfile deleted file mode 100644 index 82be301..0000000 --- a/docker/windows-libs/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -ARG DOCKER_PREFIX=wapmobil/ -FROM ${DOCKER_PREFIX}windows - -ARG LIBS_BUILD_NUMBER=9999 -ARG JOBS_COUNT=4 -ENV PATH=/opt/cmake/bin:$PATH - -WORKDIR /soft -RUN git clone -b release --single-branch --depth 1 --recursive https://git.shs.tools/SHS/libs.git - -WORKDIR /soft/libs_build_host -RUN cmake -DICU=0 -DCROSSTOOLS=1 -DBUILD_NUMBER=${LIBS_BUILD_NUMBER} ../libs \ - && make install -j${JOBS_COUNT} \ - && rm -rf * \ - && ldconfig - -WORKDIR /soft/libs_build_windows -RUN cmake -DCMAKE_INSTALL_PREFIX=/soft/windows -DICU=0 -DLIB=0 -DQGLENGINE=1 -DQGLVIEW=1 -DBUILD_NUMBER=${LIBS_BUILD_NUMBER} -DCMAKE_TOOLCHAIN_FILE=/soft/toolchain-Windows.cmake ../libs/ \ - && make install -j${JOBS_COUNT} && rm -rf * - -WORKDIR /soft/src diff --git a/qad/icons/align-bottom-center.png b/icons/align-bottom-center.png similarity index 100% rename from qad/icons/align-bottom-center.png rename to icons/align-bottom-center.png diff --git a/qad/icons/align-bottom-left.png b/icons/align-bottom-left.png similarity index 100% rename from qad/icons/align-bottom-left.png rename to icons/align-bottom-left.png diff --git a/qad/icons/align-bottom-right.png b/icons/align-bottom-right.png similarity index 100% rename from qad/icons/align-bottom-right.png rename to icons/align-bottom-right.png diff --git a/qad/icons/align-center-center.png b/icons/align-center-center.png similarity index 100% rename from qad/icons/align-center-center.png rename to icons/align-center-center.png diff --git a/qad/icons/align-center-left.png b/icons/align-center-left.png similarity index 100% rename from qad/icons/align-center-left.png rename to icons/align-center-left.png diff --git a/qad/icons/align-center-right.png b/icons/align-center-right.png similarity index 100% rename from qad/icons/align-center-right.png rename to icons/align-center-right.png diff --git a/qad/icons/align-hor.png b/icons/align-hor.png similarity index 100% rename from qad/icons/align-hor.png rename to icons/align-hor.png diff --git a/qad/icons/align-top-center.png b/icons/align-top-center.png similarity index 100% rename from qad/icons/align-top-center.png rename to icons/align-top-center.png diff --git a/qad/icons/align-top-left.png b/icons/align-top-left.png similarity index 100% rename from qad/icons/align-top-left.png rename to icons/align-top-left.png diff --git a/qad/icons/align-top-right.png b/icons/align-top-right.png similarity index 100% rename from qad/icons/align-top-right.png rename to icons/align-top-right.png diff --git a/qad/icons/align-ver.png b/icons/align-ver.png similarity index 100% rename from qad/icons/align-ver.png rename to icons/align-ver.png diff --git a/kx_utils/icons/alpha.png b/icons/alpha.png similarity index 100% rename from kx_utils/icons/alpha.png rename to icons/alpha.png diff --git a/qad/icons/application-exit.png b/icons/application-exit.png similarity index 100% rename from qad/icons/application-exit.png rename to icons/application-exit.png diff --git a/qad/icons/archive-extract.png b/icons/archive-extract.png similarity index 100% rename from qad/icons/archive-extract.png rename to icons/archive-extract.png diff --git a/qad/icons/archive-insert-directory.png b/icons/archive-insert-directory.png similarity index 100% rename from qad/icons/archive-insert-directory.png rename to icons/archive-insert-directory.png diff --git a/qad/icons/archive-insert.png b/icons/archive-insert.png similarity index 100% rename from qad/icons/archive-insert.png rename to icons/archive-insert.png diff --git a/qad/icons/arrow-down.png b/icons/arrow-down.png similarity index 100% rename from qad/icons/arrow-down.png rename to icons/arrow-down.png diff --git a/qad/icons/arrow-up.png b/icons/arrow-up.png similarity index 100% rename from qad/icons/arrow-up.png rename to icons/arrow-up.png diff --git a/qad/icons/axis_x.png b/icons/axis_x.png similarity index 100% rename from qad/icons/axis_x.png rename to icons/axis_x.png diff --git a/qad/icons/axis_y.png b/icons/axis_y.png similarity index 100% rename from qad/icons/axis_y.png rename to icons/axis_y.png diff --git a/qad/icons/blockview.png b/icons/blockview.png similarity index 100% rename from qad/icons/blockview.png rename to icons/blockview.png diff --git a/qad/icons/blockview.xcf b/icons/blockview.xcf similarity index 100% rename from qad/icons/blockview.xcf rename to icons/blockview.xcf diff --git a/qad/icons/border-line.png b/icons/border-line.png similarity index 100% rename from qad/icons/border-line.png rename to icons/border-line.png diff --git a/qad/icons/button.png b/icons/button.png similarity index 100% rename from qad/icons/button.png rename to icons/button.png diff --git a/qad/icons/case-sensitive.png b/icons/case-sensitive.png similarity index 100% rename from qad/icons/case-sensitive.png rename to icons/case-sensitive.png diff --git a/qad/icons/chardialog.png b/icons/chardialog.png similarity index 100% rename from qad/icons/chardialog.png rename to icons/chardialog.png diff --git a/qad/icons/checkbox-unchecked.png b/icons/checkbox-unchecked.png similarity index 100% rename from qad/icons/checkbox-unchecked.png rename to icons/checkbox-unchecked.png diff --git a/qad/icons/checkbox.png b/icons/checkbox.png similarity index 100% rename from qad/icons/checkbox.png rename to icons/checkbox.png diff --git a/qad/icons/clear-history.png b/icons/clear-history.png similarity index 100% rename from qad/icons/clear-history.png rename to icons/clear-history.png diff --git a/qad/icons/clineedit.png b/icons/clineedit.png similarity index 100% rename from qad/icons/clineedit.png rename to icons/clineedit.png diff --git a/qad/icons/code-error.png b/icons/code-error.png similarity index 100% rename from qad/icons/code-error.png rename to icons/code-error.png diff --git a/qad/icons/code-parents.png b/icons/code-parents.png similarity index 100% rename from qad/icons/code-parents.png rename to icons/code-parents.png diff --git a/qad/icons/code-struct.png b/icons/code-struct.png similarity index 100% rename from qad/icons/code-struct.png rename to icons/code-struct.png diff --git a/qad/icons/code-union.png b/icons/code-union.png similarity index 100% rename from qad/icons/code-union.png rename to icons/code-union.png diff --git a/qad/icons/code-variable.png b/icons/code-variable.png similarity index 100% rename from qad/icons/code-variable.png rename to icons/code-variable.png diff --git a/qad/icons/code-word.png b/icons/code-word.png similarity index 100% rename from qad/icons/code-word.png rename to icons/code-word.png diff --git a/qad/icons/colorbutton.png b/icons/colorbutton.png similarity index 100% rename from qad/icons/colorbutton.png rename to icons/colorbutton.png diff --git a/qad/icons/configure.png b/icons/configure.png similarity index 100% rename from qad/icons/configure.png rename to icons/configure.png diff --git a/qad/icons/configure_16.png b/icons/configure_16.png similarity index 100% rename from qad/icons/configure_16.png rename to icons/configure_16.png diff --git a/qad/icons/database.png b/icons/database.png similarity index 100% rename from qad/icons/database.png rename to icons/database.png diff --git a/qad/icons/dialog-cancel.png b/icons/dialog-cancel.png similarity index 100% rename from qad/icons/dialog-cancel.png rename to icons/dialog-cancel.png diff --git a/qad/icons/dialog-close.png b/icons/dialog-close.png similarity index 100% rename from qad/icons/dialog-close.png rename to icons/dialog-close.png diff --git a/qad/icons/dialog-information.png b/icons/dialog-information.png similarity index 100% rename from qad/icons/dialog-information.png rename to icons/dialog-information.png diff --git a/qad/icons/dialog-ok-apply.png b/icons/dialog-ok-apply.png similarity index 100% rename from qad/icons/dialog-ok-apply.png rename to icons/dialog-ok-apply.png diff --git a/qad/icons/dialog-warning.png b/icons/dialog-warning.png similarity index 100% rename from qad/icons/dialog-warning.png rename to icons/dialog-warning.png diff --git a/qad/icons/document-close.png b/icons/document-close.png similarity index 100% rename from qad/icons/document-close.png rename to icons/document-close.png diff --git a/qad/icons/document-edit.png b/icons/document-edit.png similarity index 100% rename from qad/icons/document-edit.png rename to icons/document-edit.png diff --git a/qad/icons/document-new.png b/icons/document-new.png similarity index 100% rename from qad/icons/document-new.png rename to icons/document-new.png diff --git a/qad/icons/document-open-recent.png b/icons/document-open-recent.png similarity index 100% rename from qad/icons/document-open-recent.png rename to icons/document-open-recent.png diff --git a/qad/icons/document-open.png b/icons/document-open.png similarity index 100% rename from qad/icons/document-open.png rename to icons/document-open.png diff --git a/qad/icons/document-open_16.png b/icons/document-open_16.png similarity index 100% rename from qad/icons/document-open_16.png rename to icons/document-open_16.png diff --git a/qad/icons/document-print.png b/icons/document-print.png similarity index 100% rename from qad/icons/document-print.png rename to icons/document-print.png diff --git a/qad/icons/document-revert.png b/icons/document-revert.png similarity index 100% rename from qad/icons/document-revert.png rename to icons/document-revert.png diff --git a/qad/icons/document-save-all.png b/icons/document-save-all.png similarity index 100% rename from qad/icons/document-save-all.png rename to icons/document-save-all.png diff --git a/qad/icons/document-save-as.png b/icons/document-save-as.png similarity index 100% rename from qad/icons/document-save-as.png rename to icons/document-save-as.png diff --git a/qad/icons/document-save.png b/icons/document-save.png similarity index 100% rename from qad/icons/document-save.png rename to icons/document-save.png diff --git a/qad/icons/draw-ellipse.png b/icons/draw-ellipse.png similarity index 100% rename from qad/icons/draw-ellipse.png rename to icons/draw-ellipse.png diff --git a/qad/icons/draw-line.png b/icons/draw-line.png similarity index 100% rename from qad/icons/draw-line.png rename to icons/draw-line.png diff --git a/qad/icons/draw-rectangle.png b/icons/draw-rectangle.png similarity index 100% rename from qad/icons/draw-rectangle.png rename to icons/draw-rectangle.png diff --git a/qad/icons/draw-text.png b/icons/draw-text.png similarity index 100% rename from qad/icons/draw-text.png rename to icons/draw-text.png diff --git a/qad/icons/ecombobox.png b/icons/ecombobox.png similarity index 100% rename from qad/icons/ecombobox.png rename to icons/ecombobox.png diff --git a/qad/icons/edit-clear-locationbar-rtl.png b/icons/edit-clear-locationbar-rtl.png similarity index 100% rename from qad/icons/edit-clear-locationbar-rtl.png rename to icons/edit-clear-locationbar-rtl.png diff --git a/qad/icons/edit-clear.png b/icons/edit-clear.png similarity index 100% rename from qad/icons/edit-clear.png rename to icons/edit-clear.png diff --git a/qad/icons/edit-copy.png b/icons/edit-copy.png similarity index 100% rename from qad/icons/edit-copy.png rename to icons/edit-copy.png diff --git a/qad/icons/edit-delete.png b/icons/edit-delete.png similarity index 100% rename from qad/icons/edit-delete.png rename to icons/edit-delete.png diff --git a/project_fs/icons/edit-find.png b/icons/edit-find.png similarity index 100% rename from project_fs/icons/edit-find.png rename to icons/edit-find.png diff --git a/qad/icons/edit-find_16.png b/icons/edit-find_16.png similarity index 100% rename from qad/icons/edit-find_16.png rename to icons/edit-find_16.png diff --git a/qad/icons/edit-guides.png b/icons/edit-guides.png similarity index 100% rename from qad/icons/edit-guides.png rename to icons/edit-guides.png diff --git a/qad/icons/edit-paste.png b/icons/edit-paste.png similarity index 100% rename from qad/icons/edit-paste.png rename to icons/edit-paste.png diff --git a/qad/icons/edit-redo.png b/icons/edit-redo.png similarity index 100% rename from qad/icons/edit-redo.png rename to icons/edit-redo.png diff --git a/qad/icons/edit-table-insert-row-below.png b/icons/edit-table-insert-row-below.png similarity index 100% rename from qad/icons/edit-table-insert-row-below.png rename to icons/edit-table-insert-row-below.png diff --git a/qad/icons/edit-undo.png b/icons/edit-undo.png similarity index 100% rename from qad/icons/edit-undo.png rename to icons/edit-undo.png diff --git a/qad/icons/edockwidget.png b/icons/edockwidget.png similarity index 100% rename from qad/icons/edockwidget.png rename to icons/edockwidget.png diff --git a/qad/icons/etabwidget.png b/icons/etabwidget.png similarity index 100% rename from qad/icons/etabwidget.png rename to icons/etabwidget.png diff --git a/qad/icons/evalspinbox.png b/icons/evalspinbox.png similarity index 100% rename from qad/icons/evalspinbox.png rename to icons/evalspinbox.png diff --git a/qad/icons/expand_s_x.png b/icons/expand_s_x.png similarity index 100% rename from qad/icons/expand_s_x.png rename to icons/expand_s_x.png diff --git a/qad/icons/expand_s_y.png b/icons/expand_s_y.png similarity index 100% rename from qad/icons/expand_s_y.png rename to icons/expand_s_y.png diff --git a/qad/icons/expand_x.png b/icons/expand_x.png similarity index 100% rename from qad/icons/expand_x.png rename to icons/expand_x.png diff --git a/qad/icons/expand_y.png b/icons/expand_y.png similarity index 100% rename from qad/icons/expand_y.png rename to icons/expand_y.png diff --git a/qad/icons/f1.png b/icons/f1.png similarity index 100% rename from qad/icons/f1.png rename to icons/f1.png diff --git a/qad/icons/format-fill-color.png b/icons/format-fill-color.png similarity index 100% rename from qad/icons/format-fill-color.png rename to icons/format-fill-color.png diff --git a/qad/icons/format-stroke-color.png b/icons/format-stroke-color.png similarity index 100% rename from qad/icons/format-stroke-color.png rename to icons/format-stroke-color.png diff --git a/qad/icons/format-text-subscript.png b/icons/format-text-subscript.png similarity index 100% rename from qad/icons/format-text-subscript.png rename to icons/format-text-subscript.png diff --git a/qad/icons/games-solve.png b/icons/games-solve.png similarity index 100% rename from qad/icons/games-solve.png rename to icons/games-solve.png diff --git a/qad/icons/go-next.png b/icons/go-next.png similarity index 100% rename from qad/icons/go-next.png rename to icons/go-next.png diff --git a/qad/icons/go-previous.png b/icons/go-previous.png similarity index 100% rename from qad/icons/go-previous.png rename to icons/go-previous.png diff --git a/qad/icons/graphic.png b/icons/graphic.png similarity index 100% rename from qad/icons/graphic.png rename to icons/graphic.png diff --git a/qad/icons/graphics.png b/icons/graphics.png similarity index 100% rename from qad/icons/graphics.png rename to icons/graphics.png diff --git a/qad/icons/historyview.png b/icons/historyview.png similarity index 100% rename from qad/icons/historyview.png rename to icons/historyview.png diff --git a/qad/icons/icons.xcf b/icons/icons.xcf similarity index 100% rename from qad/icons/icons.xcf rename to icons/icons.xcf diff --git a/kx_utils/icons/item-add.png b/icons/item-add.png similarity index 100% rename from kx_utils/icons/item-add.png rename to icons/item-add.png diff --git a/kx_utils/icons/item.png b/icons/item.png similarity index 100% rename from kx_utils/icons/item.png rename to icons/item.png diff --git a/qad/icons/lastmoves.png b/icons/lastmoves.png similarity index 100% rename from qad/icons/lastmoves.png rename to icons/lastmoves.png diff --git a/qad/icons/layer-visible-off.png b/icons/layer-visible-off.png similarity index 100% rename from qad/icons/layer-visible-off.png rename to icons/layer-visible-off.png diff --git a/qad/icons/layer-visible-on.png b/icons/layer-visible-on.png similarity index 100% rename from qad/icons/layer-visible-on.png rename to icons/layer-visible-on.png diff --git a/qad/icons/led_3.png b/icons/led_3.png similarity index 100% rename from qad/icons/led_3.png rename to icons/led_3.png diff --git a/qad/icons/led_gray.png b/icons/led_gray.png similarity index 100% rename from qad/icons/led_gray.png rename to icons/led_gray.png diff --git a/qad/icons/led_off.png b/icons/led_off.png similarity index 100% rename from qad/icons/led_off.png rename to icons/led_off.png diff --git a/qad/icons/led_on.png b/icons/led_on.png similarity index 100% rename from qad/icons/led_on.png rename to icons/led_on.png diff --git a/qad/icons/legend.png b/icons/legend.png similarity index 100% rename from qad/icons/legend.png rename to icons/legend.png diff --git a/qad/icons/list-add.png b/icons/list-add.png similarity index 100% rename from qad/icons/list-add.png rename to icons/list-add.png diff --git a/qad/icons/list-remove.png b/icons/list-remove.png similarity index 100% rename from qad/icons/list-remove.png rename to icons/list-remove.png diff --git a/qad/icons/log_parser.png b/icons/log_parser.png similarity index 100% rename from qad/icons/log_parser.png rename to icons/log_parser.png diff --git a/qad/icons/logview.png b/icons/logview.png similarity index 100% rename from qad/icons/logview.png rename to icons/logview.png diff --git a/qad/icons/mail.png b/icons/mail.png similarity index 100% rename from qad/icons/mail.png rename to icons/mail.png diff --git a/qad/icons/media-playback-pause.png b/icons/media-playback-pause.png similarity index 100% rename from qad/icons/media-playback-pause.png rename to icons/media-playback-pause.png diff --git a/qad/icons/media-playback-start.png b/icons/media-playback-start.png similarity index 100% rename from qad/icons/media-playback-start.png rename to icons/media-playback-start.png diff --git a/qad/icons/media-playback-stop.png b/icons/media-playback-stop.png similarity index 100% rename from qad/icons/media-playback-stop.png rename to icons/media-playback-stop.png diff --git a/qad/icons/media-record.png b/icons/media-record.png similarity index 100% rename from qad/icons/media-record.png rename to icons/media-record.png diff --git a/qad/icons/media-skip-forward.png b/icons/media-skip-forward.png similarity index 100% rename from qad/icons/media-skip-forward.png rename to icons/media-skip-forward.png diff --git a/kx_utils/icons/node-add.png b/icons/node-add.png similarity index 100% rename from kx_utils/icons/node-add.png rename to icons/node-add.png diff --git a/kx_utils/icons/node.png b/icons/node.png similarity index 100% rename from kx_utils/icons/node.png rename to icons/node.png diff --git a/qad/icons/pause-back.png b/icons/pause-back.png similarity index 100% rename from qad/icons/pause-back.png rename to icons/pause-back.png diff --git a/qad/icons/pause-front.png b/icons/pause-front.png similarity index 100% rename from qad/icons/pause-front.png rename to icons/pause-front.png diff --git a/qad/icons/qcodeedit.png b/icons/qcodeedit.png similarity index 100% rename from qad/icons/qcodeedit.png rename to icons/qcodeedit.png diff --git a/qad/icons/qpiconsole.png b/icons/qpiconsole.png similarity index 100% rename from qad/icons/qpiconsole.png rename to icons/qpiconsole.png diff --git a/qad/icons/qt.png b/icons/qt.png similarity index 100% rename from qad/icons/qt.png rename to icons/qt.png diff --git a/qad/icons/quickopen.png b/icons/quickopen.png similarity index 100% rename from qad/icons/quickopen.png rename to icons/quickopen.png diff --git a/qad/icons/qvariantedit.png b/icons/qvariantedit.png similarity index 100% rename from qad/icons/qvariantedit.png rename to icons/qvariantedit.png diff --git a/qad/icons/scroll_spin.png b/icons/scroll_spin.png similarity index 100% rename from qad/icons/scroll_spin.png rename to icons/scroll_spin.png diff --git a/qad/icons/select-all.png b/icons/select-all.png similarity index 100% rename from qad/icons/select-all.png rename to icons/select-all.png diff --git a/qad/icons/select-none.png b/icons/select-none.png similarity index 100% rename from qad/icons/select-none.png rename to icons/select-none.png diff --git a/qad/icons/spinslider.png b/icons/spinslider.png similarity index 100% rename from qad/icons/spinslider.png rename to icons/spinslider.png diff --git a/qad/icons/sql_table.png b/icons/sql_table.png similarity index 100% rename from qad/icons/sql_table.png rename to icons/sql_table.png diff --git a/qad/icons/tools-wizard.png b/icons/tools-wizard.png similarity index 100% rename from qad/icons/tools-wizard.png rename to icons/tools-wizard.png diff --git a/qad/icons/touchbuttframe.png b/icons/touchbuttframe.png similarity index 100% rename from qad/icons/touchbuttframe.png rename to icons/touchbuttframe.png diff --git a/qad/icons/touchbutton.png b/icons/touchbutton.png similarity index 100% rename from qad/icons/touchbutton.png rename to icons/touchbutton.png diff --git a/qad/icons/touchslider.png b/icons/touchslider.png similarity index 100% rename from qad/icons/touchslider.png rename to icons/touchslider.png diff --git a/qad/icons/transform-move.png b/icons/transform-move.png similarity index 100% rename from qad/icons/transform-move.png rename to icons/transform-move.png diff --git a/qad/icons/variable-add.png b/icons/variable-add.png similarity index 100% rename from qad/icons/variable-add.png rename to icons/variable-add.png diff --git a/qad/icons/variable-copy.png b/icons/variable-copy.png similarity index 100% rename from qad/icons/variable-copy.png rename to icons/variable-copy.png diff --git a/qad/icons/variable-edit.png b/icons/variable-edit.png similarity index 100% rename from qad/icons/variable-edit.png rename to icons/variable-edit.png diff --git a/qad/icons/variable-remove.png b/icons/variable-remove.png similarity index 100% rename from qad/icons/variable-remove.png rename to icons/variable-remove.png diff --git a/qad/icons/view-autofit.png b/icons/view-autofit.png similarity index 100% rename from qad/icons/view-autofit.png rename to icons/view-autofit.png diff --git a/qad/icons/view-fullscreen.png b/icons/view-fullscreen.png similarity index 100% rename from qad/icons/view-fullscreen.png rename to icons/view-fullscreen.png diff --git a/qad/icons/view-grid.png b/icons/view-grid.png similarity index 100% rename from qad/icons/view-grid.png rename to icons/view-grid.png diff --git a/qad/icons/view-preview.png b/icons/view-preview.png similarity index 100% rename from qad/icons/view-preview.png rename to icons/view-preview.png diff --git a/qad/icons/view-refresh.png b/icons/view-refresh.png similarity index 100% rename from qad/icons/view-refresh.png rename to icons/view-refresh.png diff --git a/qad/icons/z-bottom.png b/icons/z-bottom.png similarity index 100% rename from qad/icons/z-bottom.png rename to icons/z-bottom.png diff --git a/qad/icons/z-down.png b/icons/z-down.png similarity index 100% rename from qad/icons/z-down.png rename to icons/z-down.png diff --git a/qad/icons/z-top.png b/icons/z-top.png similarity index 100% rename from qad/icons/z-top.png rename to icons/z-top.png diff --git a/qad/icons/z-up.png b/icons/z-up.png similarity index 100% rename from qad/icons/z-up.png rename to icons/z-up.png diff --git a/qad/icons/zoom-draw.png b/icons/zoom-draw.png similarity index 100% rename from qad/icons/zoom-draw.png rename to icons/zoom-draw.png diff --git a/qad/icons/zoom-fit-best.png b/icons/zoom-fit-best.png similarity index 100% rename from qad/icons/zoom-fit-best.png rename to icons/zoom-fit-best.png diff --git a/qad/icons/zoom-in.png b/icons/zoom-in.png similarity index 100% rename from qad/icons/zoom-in.png rename to icons/zoom-in.png diff --git a/qad/icons/zoom-original.png b/icons/zoom-original.png similarity index 100% rename from qad/icons/zoom-original.png rename to icons/zoom-original.png diff --git a/qad/icons/zoom-out.png b/icons/zoom-out.png similarity index 100% rename from qad/icons/zoom-out.png rename to icons/zoom-out.png diff --git a/qad/icons/zoom-range.png b/icons/zoom-range.png similarity index 100% rename from qad/icons/zoom-range.png rename to icons/zoom-range.png diff --git a/qad/icons/zoom-rect.png b/icons/zoom-rect.png similarity index 100% rename from qad/icons/zoom-rect.png rename to icons/zoom-rect.png diff --git a/qad/icons/zoom-select.png b/icons/zoom-select.png similarity index 100% rename from qad/icons/zoom-select.png rename to icons/zoom-select.png diff --git a/kx_utils/CMakeLists.txt b/kx_utils/CMakeLists.txt deleted file mode 100644 index 80da37a..0000000 --- a/kx_utils/CMakeLists.txt +++ /dev/null @@ -1,76 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -project(kx_utils) -if (POLICY CMP0017) - cmake_policy(SET CMP0017 NEW) -endif() -if (NOT LIBPROJECT) - find_package(PIP REQUIRED) -endif () -if (MINGW) - find_package(MinGW REQUIRED) -endif() -include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${PIP_INCLUDES}) -set(KX_PULT_NAME "kx_pult") -option(KX_PULT "Build ${KX_PULT_NAME}" 1) -option(LIB "System install" 1) -option(DEBUG "Build with -g3" 0) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall") -if (DEBUG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3") -endif() -set(CPPS_UTILS "kx_coeffs.cpp" "piprotocol.cpp") -set(HDRS_UTILS "kx_coeffs.h" "kx_protocol_x.h" "kx_protocol_c.h" "piprotocol.h") -if (DEFINED ENV{QNX_HOST}) - add_library(${PROJECT_NAME} STATIC ${CPPS_UTILS}) -else() - add_library(${PROJECT_NAME} SHARED ${CPPS_UTILS}) -endif() -target_link_libraries(${PROJECT_NAME} ${PIP_LIBRARY}) -message(STATUS "Building ${PROJECT_NAME}") -if (NOT DEFINED ENV{QNX_HOST}) - if (KX_PULT) - find_package(Qt4 REQUIRED) - find_package(QAD REQUIRED) - find_package(OpenGL REQUIRED) - include_directories(${QT_INCLUDES} ${QAD_INCLUDES}) - set(CPPS "kx_pult.cpp" "kx_pult.h" "kx_pult.ui" "main_kx_pult.cpp") - set(MOCS "kx_pult.h") - file(GLOB UIS "*.ui") - file(GLOB RES "*.qrc") - qt4_wrap_cpp(CMOCS ${MOCS} OPTIONS -nw) - qt4_wrap_ui(CUIS ${UIS}) - qt4_add_resources(RESS ${RES}) - add_executable(${KX_PULT_NAME} WIN32 ${CPPS} ${CMOCS} ${CUIS} ${RESS} ${MOCS}) - set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${OPENGL_LIBRARIES} ${PIP_LIBRARY} qad_graphic4 qad_utils4 qad_widgets4) - target_link_libraries(${KX_PULT_NAME} ${LIBS} ${PROJECT_NAME}) - endif() -endif() -if (LIB) - list(APPEND _ALL_TARGETS ${PROJECT_NAME}) - set(_ALL_TARGETS ${_ALL_TARGETS} PARENT_SCOPE) - if (WIN32) - set(CMAKE_INSTALL_PREFIX ${MINGW_DIR}) - install(FILES ${HDRS_UTILS} DESTINATION ${MINGW_INCLUDE}) - install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_LIB}) - install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${MINGW_BIN}) - else() - if (DEFINED ANDROID_PLATFORM) - set(CMAKE_INSTALL_PREFIX ${ANDROID_SYSTEM_LIBRARY_PATH}/usr) - else() - set(CMAKE_INSTALL_PREFIX /usr/local) - endif() - install(FILES ${HDRS_UTILS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include) - install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) - endif() - message(STATUS "Install ${PROJECT_NAME} to system \"${CMAKE_INSTALL_PREFIX}\"") -else() - install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) - install(TARGETS ${PROJECT_NAME} DESTINATION lib) - install(FILES ${HDRS_UTILS} DESTINATION include) - message(STATUS "Install ${PROJECT_NAME} to local \"bin\", \"lib\" and \"include\"") -endif() -if (NOT DEFINED ENV{QNX_HOST}) - if (KX_PULT) - install(TARGETS ${KX_PULT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) - endif() -endif() diff --git a/kx_utils/clean b/kx_utils/clean deleted file mode 100644 index e1d5feb..0000000 --- a/kx_utils/clean +++ /dev/null @@ -1,4 +0,0 @@ -#! /bin/bash -VERBOSE=1 make clean -rm -rvf CMakeFiles -rm -vf CMakeCache.txt Makefile cmake_install.cmake install_manifest.txt *.user* *~ *cxx moc_* ui_* qrc_* *.o diff --git a/kx_utils/clean.bat b/kx_utils/clean.bat deleted file mode 100644 index 3a657d9..0000000 --- a/kx_utils/clean.bat +++ /dev/null @@ -1,4 +0,0 @@ -#make clean -del /q /f /s CMakeFiles -rmdir /q /s CMakeFiles -del /q /f CMakeCache.txt Makefile cmake_install.cmake install_manifest.txt *.user* *~ *cxx moc_* ui_* qrc_* *.o *.exe *.a *.dll *.lib core *.qrc.depends diff --git a/kx_utils/icons/accessories-calculator.png b/kx_utils/icons/accessories-calculator.png deleted file mode 100644 index 1b1dd1e..0000000 Binary files a/kx_utils/icons/accessories-calculator.png and /dev/null differ diff --git a/kx_utils/icons/archive-extract.png b/kx_utils/icons/archive-extract.png deleted file mode 100644 index f6f2a5d..0000000 Binary files a/kx_utils/icons/archive-extract.png and /dev/null differ diff --git a/kx_utils/icons/document-export.png b/kx_utils/icons/document-export.png deleted file mode 100644 index 9e1b6a6..0000000 Binary files a/kx_utils/icons/document-export.png and /dev/null differ diff --git a/kx_utils/icons/document-import.png b/kx_utils/icons/document-import.png deleted file mode 100644 index 97e683a..0000000 Binary files a/kx_utils/icons/document-import.png and /dev/null differ diff --git a/kx_utils/icons/document-open.png b/kx_utils/icons/document-open.png deleted file mode 100644 index 8ba5441..0000000 Binary files a/kx_utils/icons/document-open.png and /dev/null differ diff --git a/kx_utils/icons/document-save-.png b/kx_utils/icons/document-save-.png deleted file mode 100644 index 7fa489c..0000000 Binary files a/kx_utils/icons/document-save-.png and /dev/null differ diff --git a/kx_utils/icons/edit-clear-.png b/kx_utils/icons/edit-clear-.png deleted file mode 100644 index 631ed44..0000000 Binary files a/kx_utils/icons/edit-clear-.png and /dev/null differ diff --git a/kx_utils/icons/edit-find-.png b/kx_utils/icons/edit-find-.png deleted file mode 100644 index 64a1e28..0000000 Binary files a/kx_utils/icons/edit-find-.png and /dev/null differ diff --git a/kx_utils/icons/expand_s_x.png b/kx_utils/icons/expand_s_x.png deleted file mode 100644 index b66cb40..0000000 Binary files a/kx_utils/icons/expand_s_x.png and /dev/null differ diff --git a/kx_utils/icons/expand_s_y.png b/kx_utils/icons/expand_s_y.png deleted file mode 100644 index c2e8f78..0000000 Binary files a/kx_utils/icons/expand_s_y.png and /dev/null differ diff --git a/kx_utils/icons/expand_x.png b/kx_utils/icons/expand_x.png deleted file mode 100644 index 217e3ea..0000000 Binary files a/kx_utils/icons/expand_x.png and /dev/null differ diff --git a/kx_utils/icons/expand_y.png b/kx_utils/icons/expand_y.png deleted file mode 100644 index fedf936..0000000 Binary files a/kx_utils/icons/expand_y.png and /dev/null differ diff --git a/kx_utils/icons/layer-visible-off.png b/kx_utils/icons/layer-visible-off.png deleted file mode 100644 index 5f87dce..0000000 Binary files a/kx_utils/icons/layer-visible-off.png and /dev/null differ diff --git a/kx_utils/icons/layer-visible-on.png b/kx_utils/icons/layer-visible-on.png deleted file mode 100644 index b240552..0000000 Binary files a/kx_utils/icons/layer-visible-on.png and /dev/null differ diff --git a/kx_utils/icons/media-playback-pause.png b/kx_utils/icons/media-playback-pause.png deleted file mode 100644 index 5c7d128..0000000 Binary files a/kx_utils/icons/media-playback-pause.png and /dev/null differ diff --git a/kx_utils/icons/media-playback-stop.png b/kx_utils/icons/media-playback-stop.png deleted file mode 100644 index 650874f..0000000 Binary files a/kx_utils/icons/media-playback-stop.png and /dev/null differ diff --git a/kx_utils/icons/media-record.png b/kx_utils/icons/media-record.png deleted file mode 100644 index f926a8f..0000000 Binary files a/kx_utils/icons/media-record.png and /dev/null differ diff --git a/kx_utils/icons/view-refresh.png b/kx_utils/icons/view-refresh.png deleted file mode 100644 index afa2a9d..0000000 Binary files a/kx_utils/icons/view-refresh.png and /dev/null differ diff --git a/kx_utils/icons/zoom-fit-height.png b/kx_utils/icons/zoom-fit-height.png deleted file mode 100644 index 32e2190..0000000 Binary files a/kx_utils/icons/zoom-fit-height.png and /dev/null differ diff --git a/kx_utils/kx_coeffs.cpp b/kx_utils/kx_coeffs.cpp deleted file mode 100644 index 940ff36..0000000 --- a/kx_utils/kx_coeffs.cpp +++ /dev/null @@ -1,194 +0,0 @@ -#include "kx_coeffs.h" -#include "kx_protocol_x.h" - -double X[KX_X_COUNT]; -PIVector K; - - -KX_Coefficients::KX_Coefficients(const PIString & config, const PIString & name, bool _pult) { - setName("kx_coeffs"); - PIConfig conf(config, PIIODevice::ReadOnly); - fname = conf.getValue(name).getValue("file", "k.dat"); - readCoeffs(); - int ns = piMaxi(conf.getValue(name).getValue("count", 0), K.size_s()); - if (ns > K.size_s()) { - K.resize(ns, 0.f); - formulas.resize(ns); - writeCoeffs(); - } - config_ = config; - name_ = name; - pult_ = _pult; - k_protocol = 0; - renew(); - //readCoeffs(); -} - - -KX_Coefficients::~KX_Coefficients() { - stop(); - k_protocol->stop(); - delete k_protocol; -} - - -void KX_Coefficients::readCoeffs() { - { - PIConfig conf(fname, PIIODevice::ReadOnly); - int cnt = conf.rootEntry().childCount(); - K.resize(cnt); - formulas.resize(cnt); - PIString kn, cf; - for (int i = 0; i < cnt; i++) { - kn = "k" + PIString::fromNumber(i); - K[i] = (double)conf.getValue(kn, 0.f); - cf = conf.getValue(kn + ".formula", ""); - if (cf.isEmpty()) cf = PIString::fromNumber(K[i]); - formulas[i] = cf; - } - } - k_content = PIFile(fname, PIIODevice::ReadOnly).readAll(); - //piCout << k_content.size(); - piCoutObj << "Readed" << K.size_s() << "coefficients in" << k_content.size_s() << "bytes"; - coeffs_cnt = K.size_s(); -} - - -void KX_Coefficients::writeCoeffs() { - PIFile::remove(fname); - PIFile conf(fname, PIIODevice::ReadWrite); - //conf.clear(); - for (int i = 0; i < K.size_s(); i++) { - conf << "k" + PIString::fromNumber(i) << " = " << PIString::fromNumber(K[i]).replaceAll(",", ".") << "\n"; - conf << "k" + PIString::fromNumber(i) << ".formula = " << formulas[i] << "\n"; - } - //conf.close(); - //conf.writeAll(); - k_content = conf.readAll(); - //piCout << k_content.size(); - piCoutObj << "Written" << K.size_s() << "coefficients in" << k_content.size_s() << "bytes"; - coeffs_cnt = K.size_s(); -} - - -void KX_Coefficients::setKFile(const PIString & f) { - fname = f; - readCoeffs(); -} - - -void KX_Coefficients::sendCoeffs() { - stop(); - int curcnt, pcnt = (k_content.size_s() - 1) / __BYTES_IN_PACKET + 1; - k_protocol->to_k.full_count = k_content.size_s(); - for (int i = 0; i < pcnt; i++) { - k_protocol->to_k.first_index = i * __BYTES_IN_PACKET; - if (i == pcnt - 1) curcnt = k_content.size_s() % __BYTES_IN_PACKET; - else curcnt = __BYTES_IN_PACKET; - //cout << "send " << curcnt << " coeffs\n"; - k_protocol->to_k.count = curcnt; - memcpy(k_protocol->to_k.coeffs, k_content.data(k_protocol->to_k.first_index), curcnt); - //for (int j = 0; j < curcnt; j++) k_protocol->to_k.coeffs[j] = K.at(k_protocol->to_k.first_index + j); - k_protocol->send(); - piMSleep(5); - } - //cout << "waiting for commit ...\n"; - waitingCommit = true; - tm.reset(); - start(10); -} - - -void KX_Coefficients::receiveCoeffs() { - stop(); - k_protocol->to_k.full_count = k_protocol->to_k.first_index = k_protocol->to_k.count = -6; - k_protocol->send(); - //cout << "request send\n"; - //cout << "waiting for receive ...\n"; - waitingCommit = false; - tm.reset(); - start(10); -} - - -void KX_Coefficients::received(bool correct) { - //cout << "kpi received " << correct << endl; - if (!correct) return; - k_syns = k_protocol->from_k; - if (waitingCommit) { - if (k_syns.first_index != -1 || - k_syns.full_count != -1 || - k_syns.count != -k_content.size_s()) return; - //cout << "commit received\n"; - waitingCommit = false; - stop(); - //cout << "send succeed\n"; - //emit sendSucceed(); - sendSucceed(); - return; - } else { - if (k_syns.first_index == -6 && k_syns.full_count == -6 && k_syns.count == -6) { - //cout << "request received\n"; - sendCoeffs(); - return; - }; - } - if (k_syns.first_index < 0 || k_syns.count < 0) return; - if (k_syns.first_index == 0) { - //cout << "first receive\n"; - k_tmp.resize(k_syns.full_count); - received_cnt = 0; - } - //for (int i = 0; i < k_syns.count; i++) K.at(k_syns.first_index + i) = k_syns.coeffs[i]; - //piCout << k_tmp.size() << k_syns.first_index << k_syns.count; - memcpy(k_tmp.data(k_syns.first_index), k_syns.coeffs, k_syns.count); - received_cnt += k_syns.count; - tm.reset(); - //cout << "received " << k_syns.count << " bytes with " << k_syns.first_index << " first\n"; - if (received_cnt < k_syns.full_count) return; - //cout << "finally received " << received_cnt << " bytes\n"; - stop(); - PIFile::remove(fname); - PIFile conf(fname, PIIODevice::ReadWrite); - conf.write(k_tmp.data(), k_tmp.size_s()); - conf.close(); - readCoeffs(); - //writeCoeffs(); - k_protocol->to_k.full_count = k_protocol->to_k.first_index = -1; - k_protocol->to_k.count = -received_cnt; - k_protocol->send(); - waitingCommit = false; - //emit receiveSucceed(); - receiveSucceed(); - //cout << "receive succeed\n"; -} - - -void KX_Coefficients::renew() { - if (k_protocol != 0) { - k_protocol->stop(); - delete k_protocol; - } - k_protocol = new __KPi(config_, name_, pult_); - CONNECT1(void, bool, k_protocol, received, this, received) - waitingCommit = false; -} - - -void KX_Coefficients::tick(void * , int ) { - //piCout << "timer" << tm.elapsed_s(); - if (tm.elapsed_s() < 10.) return; - if (waitingCommit) { - //cout << "commit timeout\n"; - //cout << "send failed\n"; - //emit sendFailed(); - sendFailed(); - } else { - //cout << "receive timeout\n"; - //cout << "receive failed\n"; - //emit receiveFailed(); - receiveFailed(); - } - waitingCommit = false; - stop(); -} diff --git a/kx_utils/kx_coeffs.h b/kx_utils/kx_coeffs.h deleted file mode 100644 index e6d31b7..0000000 --- a/kx_utils/kx_coeffs.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef KX_COEFFS_H -#define KX_COEFFS_H - -#include "piprotocol.h" - -#define __BYTES_IN_PACKET 4000 - -extern PIVector K; - -class __KPi: public PIProtocol -{ - PIOBJECT_SUBCLASS(__KPi, PIProtocol) -public: -#pragma pack (push, 1) - struct KX_K_Sync { - uchar type; - uchar addr_to; - int count; - int full_count; - int first_index; - uchar coeffs[__BYTES_IN_PACKET]; - uint checksum; - }; -#pragma pack (pop) - __KPi(const PIString & config, const PIString & name, bool _pult = false): PIProtocol(config, name, &from_k, 2, &(from_k.count), sizeof(from_k) - 2, &to_k, sizeof(to_k)) { - PIConfig conf(config, PIIODevice::ReadOnly); - PIConfig::Entry ce = conf.getValue(name); - to_k.type = from_k.type = ce.getValue("type", 0xA); - to_k.addr_to = ce.getValue("addr_k", 0x15); - from_k.addr_to = ce.getValue("addr_pult", 0x75); - if (_pult) piSwap(to_k.addr_to, from_k.addr_to); - packetExtractor()->setHeader(PIByteArray(&from_k, 2)); - start(); - } - KX_K_Sync to_k, from_k; -private: - bool validate() { - return (from_k.checksum == checksum_i(&from_k, sizeof(from_k) - 4)); - } - bool aboutSend() { - to_k.checksum = checksum_i(&to_k, sizeof(to_k) - 4); - return true; - } -}; - - -class KX_Coefficients: public PITimer -{ - PIOBJECT_SUBCLASS(KX_Coefficients, PITimer) - friend class KX_Pult; -public: - KX_Coefficients(const PIString & config, const PIString & name = "k", bool _pult = false); - ~KX_Coefficients(); - - void readCoeffs(); - void writeCoeffs(); - - void sendCoeffs(); - void receiveCoeffs(); - - bool isReady() const {return !waitingCommit;} - const PIString & fileName() const {return fname;} - const PIString * fileName_ptr() const {return &fname;} - int coeffsCount() {coeffs_cnt = K.size_s(); return coeffs_cnt;} - const int * coeffsCount_ptr() const {return &coeffs_cnt;} - - const PIString & formula(int index) const {return formulas[index];} - void setFormula(int index, const PIString & f) {formulas[index] = f;} - - void setKFile(const PIString & f); - - EVENT(sendSucceed) - EVENT(sendFailed) - EVENT(receiveSucceed) - EVENT(receiveFailed) - - - __KPi * k_protocol; - -private: - EVENT_HANDLER1(void, received, bool, correct); - void renew(); - void tick(void *, int); - - __KPi::KX_K_Sync k_syns; - bool pult_, waitingCommit; - int received_cnt, coeffs_cnt; - PIString fname, config_, name_; - PIStringList formulas; - PIByteArray k_content, k_tmp; - PITimeMeasurer tm; - -}; - -#endif // KX_COEFFS_H diff --git a/kx_utils/kx_protocol_c.h b/kx_utils/kx_protocol_c.h deleted file mode 100644 index 66a5441..0000000 --- a/kx_utils/kx_protocol_c.h +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef KX_PROTOCOL_C_H -#define KX_PROTOCOL_C_H - -#include "piprotocol.h" - - -#pragma pack (push, 1) - - -struct KX_C_Header { - uchar type; - uchar addr_to; -}; - - - -struct KX_C_Command: KX_C_Header { - KX_C_Command() {command = -1;} - int command; - uint checksum; -}; - - -struct KX_C_Event: KX_C_Header { - KX_C_Event() {event = -1;} - PISystemTime time; - int event; - uint checksum; -}; - - -#pragma pack (pop) - - -// Client side - -class KX_Protocol_C: public PIProtocol -{ - PIOBJECT_SUBCLASS(KX_Protocol_C, PIProtocol) -public: - KX_Protocol_C(const PIString & config, const PIString & name = "c"): PIProtocol(config, name, &from_buff, 2, &(from_buff.command), sizeof(from_buff) - 2, &to_pult, sizeof(to_pult)) { - PIConfig conf(config, PIIODevice::ReadOnly); - PIConfig::Entry ce = conf.getValue(name); - to_pult.type = from_buff.type = ce.getValue("type", 0xC); - to_pult.addr_to = ce.getValue("addr_pult", 0x15); - from_buff.addr_to = ce.getValue("addr_c", 0x75); - from_pult = from_buff; - packetExtractor()->setSplitMode(PIPacketExtractor::Header); - packetExtractor()->setHeader(PIByteArray(&from_buff, 2)); - startReceive(); - } - - void sendEvent(int ev) { - to_pult.time = PISystemTime::current(); - to_pult.event = ev; - send(); - } - EVENT1(commandReceived, int, command) - - KX_C_Command from_pult; - KX_C_Event to_pult; - -private: - bool validate() { - if (checksum_i(&from_buff, sizeof(from_buff) - 4) != from_buff.checksum) return false; - from_pult = from_buff; - commandReceived(from_pult.command); - return true; - } - bool aboutSend() { - to_pult.checksum = checksum_i(&to_pult, sizeof(to_pult) - 4); - return true; - } - - KX_C_Command from_buff; - -}; - - - -// Pult side - -class __KX_Protocol_C: public PIProtocol -{ - PIOBJECT_SUBCLASS(__KX_Protocol_C, PIProtocol) -public: - __KX_Protocol_C(const PIString & config, const PIString & name): PIProtocol(config, name, &from_buff, 2, &(from_buff.time), sizeof(from_buff) - 2, &to_c, sizeof(to_c)) { - PIConfig conf(config, PIIODevice::ReadOnly); - PIConfig::Entry ce = conf.getValue(name); - to_c.type = from_buff.type = ce.getValue("type", 0xC); - to_c.addr_to = ce.getValue("addr_c", 0x75); - from_buff.addr_to = ce.getValue("addr_pult", 0x15); - from_c = from_buff; - packetExtractor()->setSplitMode(PIPacketExtractor::Header); - packetExtractor()->setHeader(PIByteArray(&from_buff, 2)); - startReceive(); - } - - void sendCommand(int cmd) { - to_c.command = cmd; - send(); - } - EVENT2(eventReceived, int, event, PISystemTime, time) - - KX_C_Event from_c; - KX_C_Command to_c; - -private: - bool validate() { - if (checksum_i(&from_buff, sizeof(from_buff) - 4) != from_buff.checksum) return false; - from_c = from_buff; - eventReceived(from_c.event, from_c.time); - return true; - } - bool aboutSend() { - //piCout << "send command" << to_c.command; - to_c.checksum = checksum_i(&to_c, sizeof(to_c) - 4); - return true; - } - - KX_C_Event from_buff; - -}; - - -#endif // KX_PROTOCOL_C_H diff --git a/kx_utils/kx_protocol_x.h b/kx_utils/kx_protocol_x.h deleted file mode 100644 index 4805a50..0000000 --- a/kx_utils/kx_protocol_x.h +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef KX_PROTOCOL_X_H -#define KX_PROTOCOL_X_H - -#include "piprotocol.h" - -#define KX_X_PACKET_NUM 20 -#define KX_X_COUNT 16384 - -extern double X[KX_X_COUNT]; - - -#pragma pack (push, 1) - - -struct KX_X_Header { - uchar type; - uchar addr_to; -}; - - - -struct KX_X_Numbers: KX_X_Header { - int x_num[KX_X_PACKET_NUM]; - uint checksum; -}; - - -struct KX_X_Data: KX_X_Header { - int x_num[KX_X_PACKET_NUM]; - double x_data[KX_X_PACKET_NUM]; - uint checksum; -}; - - -#pragma pack (pop) - - -// Client side - -class KX_Protocol_X: public PIProtocol -{ - PIOBJECT_SUBCLASS(KX_Protocol_X, PIProtocol) -public: - KX_Protocol_X(const PIString & config, const PIString & name = "x"): PIProtocol(config, name, &from_buff, 2, &(from_buff.x_num[0]), sizeof(from_buff) - 2, &to_pult, sizeof(to_pult)) { - PIConfig conf(config, PIIODevice::ReadOnly); - PIConfig::Entry ce = conf.getValue(name); - to_pult.type = from_buff.type = ce.getValue("type", 0xB); - to_pult.addr_to = ce.getValue("addr_pult", 0x15); - from_buff.addr_to = ce.getValue("addr_x", 0x75); - from_pult = from_buff; - for (int i = 0; i < KX_X_PACKET_NUM; ++i) - to_pult.x_num[i] = from_pult.x_num[i] = -1; - packetExtractor()->setSplitMode(PIPacketExtractor::Header); - packetExtractor()->setHeader(PIByteArray(&from_buff, 2)); - start(); - } - - KX_X_Numbers from_pult; - KX_X_Data to_pult; - -private: - bool validate() { - if (checksum_i(&from_buff, sizeof(from_buff) - 4) != from_buff.checksum) return false; - from_pult = from_buff; - return true; - } - bool aboutSend() { - for (int i = 0; i < KX_X_PACKET_NUM; ++i) { - to_pult.x_num[i] = from_pult.x_num[i]; - to_pult.x_data[i] = from_pult.x_num[i] < 0 ? 0. : X[from_pult.x_num[i]]; - } - to_pult.checksum = checksum_i(&to_pult, sizeof(to_pult) - 4); - return true; - } - - KX_X_Numbers from_buff; - -}; - - - -// Pult side - -class __KX_Protocol_X: public PIProtocol -{ - PIOBJECT_SUBCLASS(__KX_Protocol_X, PIProtocol) -public: - __KX_Protocol_X(const PIString & config, const PIString & name): PIProtocol(config, name, &from_buff, 2, &(from_buff.x_num[0]), sizeof(from_buff) - 2, &to_x, sizeof(to_x)) { - PIConfig conf(config, PIIODevice::ReadOnly); - PIConfig::Entry ce = conf.getValue(name); - to_x.type = from_buff.type = ce.getValue("type", 0xB); - to_x.addr_to = ce.getValue("addr_x", 0x75); - from_buff.addr_to = ce.getValue("addr_pult", 0x15); - from_x = from_buff; - for (int i = 0; i < KX_X_PACKET_NUM; ++i) - to_x.x_num[i] = -1; - packetExtractor()->setSplitMode(PIPacketExtractor::Header); - packetExtractor()->setHeader(PIByteArray(&from_buff, 2)); - start(); - } - - KX_X_Data from_x; - KX_X_Numbers to_x; - -private: - bool validate() { - if (checksum_i(&from_buff, sizeof(from_buff) - 4) != from_buff.checksum) return false; - from_x = from_buff; - return true; - } - bool aboutSend() { - to_x.checksum = checksum_i(&to_x, sizeof(to_x) - 4); - return true; - } - - KX_X_Data from_buff; - -}; - - -#endif // KX_PROTOCOL_X_H diff --git a/kx_utils/kx_pult.conf b/kx_utils/kx_pult.conf deleted file mode 100644 index e69de29..0000000 diff --git a/kx_utils/kx_pult.cpp b/kx_utils/kx_pult.cpp deleted file mode 100644 index 2e5fab9..0000000 --- a/kx_utils/kx_pult.cpp +++ /dev/null @@ -1,848 +0,0 @@ -#include -#include -#include -#include "kx_pult.h" -#include "ui_kx_pult.h" -#include "piqt.h" -#include "qpiconfig.h" - - -bool isNormalDouble(const double & v) { -#ifdef WINDOWS - return true; -#else - return !isnan(v) && !isinf(v); -#endif -} - - -XCheck::XCheck(int index): QWidget() { - index_ = index; - setProperty("index", index); - setMouseTracking(true); - check.setText(QString::number(index + 1) + " "); - check.setAutoFillBackground(true); - spin.setMaximum(KX_X_COUNT - 1); - QBoxLayout * l = new QBoxLayout(QBoxLayout::LeftToRight); - l->setMargin(0); - l->setSpacing(2); - l->addWidget(&check); - l->addWidget(&spin); - setLayout(l); - //check.installEventFilter(this); - //spin.installEventFilter(this); - connect(&spin, SIGNAL(valueChanged(int)), this, SLOT(spinChanged(int))); - connect(&check, SIGNAL(toggled(bool)), this, SLOT(checkChanged_(bool))); -} - - -bool XCheck::eventFilter(QObject * o, QEvent * e) { - if (e->type() == QEvent::Enter) - qApp->postEvent(this, new QEvent(e->type())); - return QWidget::eventFilter(o, e); -} - - - - -KX_Pult::KX_Pult(): QMainWindow(), config_("kx_pult.conf"), name_x("x"), name_c("c"), -config(piqt(config_), QIODevice::ReadWrite), coeffs(config_, "k", true) { - //cout << sizeof(coeffsK.k_protocol->to_k) << endl; - ui = new Ui::KX_Pult(); - ui->setupUi(this); - ui->configWidget->setQPIConfig(&config); - ui->configWidget->expandAll(); - ui->list->viewport()->installEventFilter(this); - ui->treeK->viewport()->installEventFilter(this); - ui->scrollArea->setAutoFillBackground(false); - ui->scrollAreaWidgetContents->setAutoFillBackground(false); - ui->widget->setAutoFillBackground(false); - ui->label_17->setFixedSize(preferredIconSize(1.25, this)); - log_menu.addAction(ui->actionClear); - prot_x = 0; - prot_c = 0; - show_x = config.getValue("show_x", true); - if (!show_x) - ui->tabWidget->removeTab(1); - session.setFile("session_KX_Pult.conf"); - session.addEntry(this); - session.addEntry(ui->tabWidget); - session.addEntry(ui->checkKHideEmpty); - session.addEntry(ui->checkKHideNormal); - session.addEntry(ui->checkKHideExpressions); - session.addEntry(ui->checkKAutoCalculate); - needWrite = isPause = false; - timer = 0; - //x.resize(KX_X_PACKET_NUM); - //k.resize(K_NUM); - QPalette pal = palette(); - QColor col; - ui->graphic->setGraphicsCount(0); - for (int i = 0; i < KX_X_PACKET_NUM; ++i) { - XCheck * xc = new XCheck(i); - xc->installEventFilter(this); - connect(xc, SIGNAL(valueChanged(int, int)), this, SLOT(changedX(int,int))); - connect(xc, SIGNAL(checkChanged(int, bool)), this, SLOT(toggledX(int, bool))); - col = QColor::fromHsv(360 / KX_X_PACKET_NUM * i, 255, 200); - pal.setColor(QPalette::Button, col); - pal.setColor(QPalette::Window, col); - pal.setColor(QPalette::WindowText, invertColor(col)); - xc->check.setPalette(pal); - ui->graphic->addGraphic(QString::number(i), col); - ui->graphic->setGraphicVisible(false, i); - checks << xc; - ((QGridLayout * )(ui->widgetChecks->layout()))->addWidget(xc, (i / 10) * 2, i % 10); - QLabel * lbl = new QLabel("0"); lbl->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); - values << lbl; - ((QGridLayout * )(ui->widgetChecks->layout()))->addWidget(lbl, (i / 10) * 2 + 1, i % 10); - //xc->show(); - } - renew(); - icon_record = QIcon(":/icons/media-record.png"); - icon_stop = QIcon(":/icons/media-playback-stop.png"); - outdir = dir.absolutePath(); - if (!dir.exists()) dir.mkdir(outdir); - outdir += "/"; - ui->treeK->setColumnWidth(0, 60); - ui->treeK->setColumnWidth(1, 250); - ui->treeK->setColumnWidth(3, 100); - ui->treeK->setColumnWidth(4, 100); - //ui->table->setK(coeffsK.k()->data(), coeffsK.count()); - ui->spinSize->setValue(K.size_s()); - addToList(trUtf8("Read K file \"%1\": %2 coeffs, %3 bytes").arg(PI2QString(coeffs.fileName())).arg(K.size_s()).arg(coeffs.k_content.size_s()), Qt::darkMagenta); - CONNECT(void, &coeffs, sendFailed, this, pip_sendFailed); - CONNECT(void, &coeffs, sendSucceed, this, pip_sendSucceed); - CONNECT(void, &coeffs, receiveFailed, this, pip_receiveFailed); - CONNECT(void, &coeffs, receiveSucceed, this, pip_receiveSucceed); - connect(this, SIGNAL(q_k_sendFailed()), this, SLOT(k_sendFailed()), Qt::QueuedConnection); - connect(this, SIGNAL(q_k_sendSucceed()), this, SLOT(k_sendSucceed()), Qt::QueuedConnection); - connect(this, SIGNAL(q_k_receiveFailed()), this, SLOT(k_receiveFailed()), Qt::QueuedConnection); - connect(this, SIGNAL(q_k_receiveSucceed()), this, SLOT(k_receiveSucceed()), Qt::QueuedConnection); - connect(&timer_diag, SIGNAL(timeout()), this, SLOT(updateDiag())); - connect(&session, SIGNAL(loading(QPIConfig&)), this, SLOT(loading(QPIConfig&))); - connect(&session, SIGNAL(saving(QPIConfig&)), this, SLOT(saving(QPIConfig&))); - connect(ui->checkKHideEmpty, SIGNAL(toggled(bool)), this, SLOT(filterTree())); - connect(ui->checkKHideNormal, SIGNAL(toggled(bool)), this, SLOT(filterTree())); - connect(ui->checkKHideExpressions, SIGNAL(toggled(bool)), this, SLOT(filterTree())); - connect(ui->lineKSearch, SIGNAL(textChanged(QString)), this, SLOT(filterTree())); - session.load(); - updateKDesc(); - updateCDesc(); - timer_diag.start(40); - timer_update = startTimer(25); -} - - -KX_Pult::~KX_Pult() { - session.save(); -} - - -void KX_Pult::loading(QPIConfig & conf) { - kdesc_file = conf.getValue("kdesc_file").stringValue(); - cdesc_file = conf.getValue("cdesc_file").stringValue(); -} - - -void KX_Pult::saving(QPIConfig & conf) { - conf.setValue("kdesc_file", kdesc_file); - conf.setValue("cdesc_file", cdesc_file); -} - - -bool KX_Pult::eventFilter(QObject * o, QEvent * e) { - if (o == ui->list->viewport()) { - if (e->type() == QEvent::ContextMenu) { - clear_target = 0; - log_menu.popup(((QContextMenuEvent*)e)->globalPos()); - } - return QMainWindow::eventFilter(o, e); - } - if (o == ui->treeK->viewport()) { - if (e->type() == QEvent::ContextMenu) { - clear_target = 1; - log_menu.popup(((QContextMenuEvent*)e)->globalPos()); - } - return QMainWindow::eventFilter(o, e); - } - int ind = o->property("index").toInt(); - //qDebug() << "event" << i << e->type(); - switch (e->type()) { - case QEvent::Enter: - ui->graphic->setAutoUpdate(false); - for (int i = 0; i < KX_X_PACKET_NUM; ++i) - ui->graphic->setGraphicLineWidth(ind == i ? 3. : 1., i); - ui->graphic->setAutoUpdate(true); - ui->graphic->update(); - break; - case QEvent::Leave: - ui->graphic->setAutoUpdate(false); - for (int i = 0; i < KX_X_PACKET_NUM; ++i) - ui->graphic->setGraphicLineWidth(1., i); - ui->graphic->setAutoUpdate(true); - ui->graphic->update(); - break; - default: break; - } - return QMainWindow::eventFilter(o, e); -} - - -void KX_Pult::timerEvent(QTimerEvent * e) { - if (e->timerId() == timer_update) { - if (need_update) { - need_update = false; - ui->graphic->updateGraphics(); - } - } - if (e->timerId() == timer) { - static QString sPI = QString::number(atan(1) * 4., 'f', 14).leftJustified(14); - static int cnt = 0; - int si = qMax(cnt - 6, 0); - ++cnt; - cnt %= 23; - ui->labelWait->setText(QString(si, QChar(' ')) + sPI.mid(cnt - 6, 6).trimmed()); - if (!coeffs.isReady()) return; - //ui->table->setK(coeffsK.k()->data(), coeffsK.count()); - //ui->table->showK(); - } -} - - -void KX_Pult::setControlsEnable(bool enable) { - foreach (XCheck * i, checks) - i->setEnabled(enable); - ui->buttonShowAll->setEnabled(enable); - ui->buttonHideAll->setEnabled(enable); -} - - -void KX_Pult::setX(const KX_X_Data & data) { - if (!show_x) return; - //ui->graphic->lock(); - for (int i = 0; i < KX_X_PACKET_NUM; ++i) { - if (!isNormalDouble(data.x_data[i])) continue; - ui->graphic->addPoint(data.x_data[i], i, false); - values[i]->setText(QString("(%1): %2").arg(data.x_num[i]).arg(data.x_data[i])); - } - //ui->graphic->unlock(); - if (!isPause) { - need_update = true; - } - if (!needWrite) return; - stream << QString::number(tm.elapsed() / 1000., 'f', 3) << " " << QTime::currentTime().toString("hh:mm:ss") << " " << wcnt++; - for (int i = 0; i < KX_X_PACKET_NUM; ++i) - stream << " " << QString::number(data.x_data[i], 'f', 4); - stream << "\n"; -} - - -void KX_Pult::addToList(const QString & s, const QColor & c) { - ui->list->addItem(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:ss - ") + s); - ui->list->item(ui->list->count() - 1)->setTextColor(c); - ui->list->scrollToBottom(); -} - - -void KX_Pult::on_buttonRecord_clicked() { - static bool isRec = false; - int cinc = 0; - QString str; - isRec = !isRec; - setControlsEnable(!isRec); - if (isRec) { - tm.restart(); - file.close(); - file.setFileName(outdir + getNewFileName(cinc)); - while (file.exists()) - file.setFileName(outdir + getNewFileName(cinc++)); - file.open(QIODevice::ReadWrite); - stream.setDevice(&file); - stream << "T V C"; - for (int i = 0; i < KX_X_PACKET_NUM; ++i) - stream << " X" + QString::number(checks[i]->spin.value()); - stream << "\n"; - wcnt = 0; - needWrite = true; - ui->buttonRecord->setText(trUtf8("Finish record")); - ui->buttonRecord->setIcon(icon_stop); - emit recordStarted(QFileInfo(file).completeBaseName()); - } else { - needWrite = false; - stream.setDevice(0); - file.close(); - ui->buttonRecord->setText(trUtf8("Start record")); - ui->buttonRecord->setIcon(icon_record); - emit recordStopped(QFileInfo(file).completeBaseName()); - } -} - - -void KX_Pult::on_actionClear_triggered() { - switch (clear_target) { - case 0: - ui->list->clear(); - break; - case 1: - clearSelected(); - break; - default: break; - } -} - - -void KX_Pult::clearSelected() { - QList si = ui->treeK->selectedItems(); - ui->treeK->setUpdatesEnabled(false); - ui->treeK->blockSignals(true); - foreach (QTreeWidgetItem * i, si) { - int ki = i->text(0).toInt(); - i->setText(2, ""); - coeffs.setFormula(ki, ""); - } - ui->treeK->blockSignals(false); - ui->treeK->setUpdatesEnabled(true); - if (ui->checkKAutoCalculate->isChecked()) { - QApplication::processEvents(); - calculate(); - } -} - - -QString KX_Pult::typeName(const QString & n) const { - if (n.isEmpty()) return ""; - switch (n[0].toLatin1()) { - case 'l': return trUtf8("list"); break; - case 'b': return trUtf8("bool"); break; - case 'n': return trUtf8("int"); break; - case 'f': return trUtf8("double"); break; - case 'c': return trUtf8("color"); break; - case 'r': return trUtf8("rect"); break; - case 'a': return trUtf8("rect"); break; - case 'p': return trUtf8("point"); break; - case 'v': return trUtf8("vector"); break; - case 'i': return trUtf8("IP"); break; - case 'e': return trUtf8("enum"); break; - case 'F': return trUtf8("file"); break; - case 'D': return trUtf8("dir"); break; - } - return ""; -} - - -void KX_Pult::received(bool ok) { - if (!ok) return; - setX(prot_x->from_x); -} - - -void KX_Pult::on_treeK_itemClicked(QTreeWidgetItem * item, int column) { - Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable; - if (column == 2) f |= Qt::ItemIsEditable; - item->setFlags(f); -} - - -void KX_Pult::on_treeK_itemChanged(QTreeWidgetItem * item, int column) { - if (column != 2) return; - int ki = item->text(0).toInt(); - coeffs.setFormula(ki, piqt(item->text(column))); - if (ui->checkKAutoCalculate->isChecked()) - calculate(); -} - - -QString KX_Pult::getNewFileName(int inc) { - dir.refresh(); - dir.setNameFilters(QStringList("Experiment_*.txt")); - return "Experiment_" + QDateTime::currentDateTime().toString("dd_MM_yy__hh_mm_ss") + "__" + - QString::number(dir.entryList().count() + inc) + ".txt"; -} - - -void KX_Pult::on_buttonSendK_clicked() { - on_buttonWrite_clicked(); - coeffs.sendCoeffs(); - if (timer != 0) killTimer(timer); - timer = startTimer(100); -} - - -void KX_Pult::on_buttonReceiveK_clicked() { - coeffs.receiveCoeffs(); - if (timer != 0) killTimer(timer); - timer = startTimer(100); -} - - -void KX_Pult::on_buttonShowAll_clicked() { - for (int i = 0; i < KX_X_PACKET_NUM; ++i) { - checks[i]->check.setChecked(true); - //ui->graphic->setGraphicVisible(true, i); - } -} - - -void KX_Pult::on_buttonHideAll_clicked() { - for (int i = 0; i < KX_X_PACKET_NUM; ++i) { - checks[i]->check.setChecked(false); - //ui->graphic->setGraphicVisible(false, i); - } -} - - -void KX_Pult::on_buttonRead_clicked() { - coeffs.readCoeffs(); - addToList(trUtf8("Read K file \"%1\": %2 coeffs, %3 bytes").arg(PI2QString(coeffs.fileName())).arg(K.size_s()).arg(coeffs.k_content.size_s()), Qt::darkMagenta); - updateTree(); -} - - -void KX_Pult::on_buttonWrite_clicked() { - coeffs.writeCoeffs(); - addToList(trUtf8("Write K file \"%1\": %2 coeffs, %3 bytes").arg(PI2QString(coeffs.fileName())).arg(K.size_s()).arg(coeffs.k_content.size_s()), Qt::darkMagenta); -} - - -void KX_Pult::on_buttonResize_clicked() { - K.resize(ui->spinSize->value()); - coeffs.formulas.resize(ui->spinSize->value()); - ui->spinSize->setStyleSheet(""); - updateTree(); -} - - -void KX_Pult::on_buttonSetKDesc_clicked() { - QString ret = QFileDialog::getOpenFileName(this, trUtf8("Select *.h file with K description"), kdesc_file, "C/C++ header files(*.h *.hpp);;All files(*)"); - if (ret.isEmpty()) return; - kdesc_file = QDir::current().relativeFilePath(ret); - updateKDesc(true); -} - - -void KX_Pult::on_buttonSetCDesc_clicked() { - QString ret = QFileDialog::getOpenFileName(this, trUtf8("Select *.h file with C description"), cdesc_file, "C/C++ header files(*.h *.hpp);;All files(*)"); - if (ret.isEmpty()) return; - cdesc_file = QDir::current().relativeFilePath(ret); - updateCDesc(); -} - - -void KX_Pult::on_spinSize_valueChanged(int) { - ui->spinSize->setStyleSheet(""); -} - - -void KX_Pult::k_sendFailed() { - stopWait(); - addToList(trUtf8("K not sended"), Qt::darkRed); -} - - -void KX_Pult::k_sendSucceed() { - stopWait(); - addToList(trUtf8("K sended"), Qt::darkGreen); -} - - -void KX_Pult::k_receiveFailed() { - stopWait(); - addToList(trUtf8("K not received"), Qt::darkRed); -} - - -void KX_Pult::k_receiveSucceed() { - stopWait(); - addToList(trUtf8("K received"), Qt::darkGreen); - addToList(trUtf8("Write K file \"%1\": %2 coeffs, %3 bytes").arg(PI2QString(coeffs.fileName())).arg(K.size_s()).arg(coeffs.k_content.size_s()), Qt::darkMagenta); - ui->spinSize->setValue(K.size_s()); - updateTree(); - //ui->table->setK(coeffsK.k()->data(), coeffsK.count()); -} - - -void KX_Pult::on_spinBuffer_editingFinished() { - ui->graphic->setHistorySize(ui->spinBuffer->value()); -} - - -void KX_Pult::stopWait() { - killTimer(timer); - timer = 0; - ui->labelWait->setText(" "); -} - - -void KX_Pult::updateGraph() { - ui->graphic->updateGraphics(); -} - - -void KX_Pult::updateDiag() { - ui->labelKReceiver->setText(piqt(coeffs.k_protocol->receiverDeviceName() + " - " + coeffs.k_protocol->receiverDeviceState())); - ui->labelKSender->setText(piqt(coeffs.k_protocol->senderDeviceName())); - ui->spinKSended->setValue(coeffs.k_protocol->sendCount()); - ui->spinKReceived->setValue(coeffs.k_protocol->receiveCount()); - ui->spinKWrong->setValue(coeffs.k_protocol->wrongCount()); - ui->spinKMissed->setValue(coeffs.k_protocol->missedCount()); - ui->labelKType->setText("0x" + QString::number(coeffs.k_protocol->from_k.type, 16).toUpper().rightJustified(2, '0')); - ui->labelKAddrPult->setText("0x" + QString::number(coeffs.k_protocol->from_k.addr_to, 16).toUpper().rightJustified(2, '0')); - ui->labelKAddr->setText("0x" + QString::number(coeffs.k_protocol->to_k.addr_to, 16).toUpper().rightJustified(2, '0')); - - ui->labelXReceiver->setText(piqt(prot_x->receiverDeviceName() + " - " + prot_x->receiverDeviceState())); - ui->labelXSender->setText(piqt(prot_x->senderDeviceName())); - ui->spinXSended->setValue(prot_x->sendCount()); - ui->spinXReceived->setValue(prot_x->receiveCount()); - ui->spinXWrong->setValue(prot_x->wrongCount()); - ui->spinXMissed->setValue(prot_x->missedCount()); - ui->labelXType->setText("0x" + QString::number(prot_x->from_x.type, 16).toUpper().rightJustified(2, '0')); - ui->labelXAddrPult->setText("0x" + QString::number(prot_x->from_x.addr_to, 16).toUpper().rightJustified(2, '0')); - ui->labelXAddr->setText("0x" + QString::number(prot_x->to_x.addr_to, 16).toUpper().rightJustified(2, '0')); - - ui->labelCReceiver->setText(piqt(prot_c->receiverDeviceName() + " - " + prot_c->receiverDeviceState())); - ui->labelCSender->setText(piqt(prot_c->senderDeviceName())); - ui->spinCSended->setValue(prot_c->sendCount()); - ui->spinCReceived->setValue(prot_c->receiveCount()); - ui->spinCWrong->setValue(prot_c->wrongCount()); - ui->spinCMissed->setValue(prot_c->missedCount()); - ui->labelCType->setText("0x" + QString::number(prot_c->from_c.type, 16).toUpper().rightJustified(2, '0')); - ui->labelCAddrPult->setText("0x" + QString::number(prot_c->from_c.addr_to, 16).toUpper().rightJustified(2, '0')); - ui->labelCAddr->setText("0x" + QString::number(prot_c->to_c.addr_to, 16).toUpper().rightJustified(2, '0')); -} - - -int KX_Pult::parseHeader(const QString & file, QMap & map) { - map.clear(); - QFile f(file); - if (!f.open(QIODevice::ReadOnly)) { - updateTree(); - addToList(trUtf8("Update descriptions from \"%1\": error").arg(file), Qt::darkRed); - return 0; - } - addToList(trUtf8("Update descriptions from \"%1\"").arg(file), Qt::darkMagenta); - QTextStream s(&f); - int cind = -1; - bool found = false; - //qDebug() << "\nparse" << file; - while (!s.atEnd()) { - QString line = s.readLine().trimmed(), num, name, type, comment; - int i = line.indexOf("//"); - if (i >= 0) { - comment = line.right(line.length() - i - 2); - type = comment.left(1); - comment = comment.right(comment.length() - 1).trimmed(); - line = line.left(i).trimmed(); - } - if (line.isEmpty()) continue; - if (line.contains("enum")) { - found = true; - continue; - } - if (!found) continue; - if (line.contains('}')) - break; - line.remove(',').remove(' ').remove('\t'); - i = line.indexOf("="); - if (i >= 0) { - num = line.right(line.length() - i - 1).trimmed(); - line = line.left(i).trimmed(); - } - name = line; - if (num.isEmpty()) - ++cind; - else - cind = Q2PIString(num).toInt(); - KDesc kd; - kd.index = cind; - kd.name = name; - kd.type = type; - kd.comment = comment; - map[kd.index] = kd; - //qDebug() << name << cind << type << comment; - } - cind++; - return cind; -} - - -void KX_Pult::updateKDesc(bool ask_move) { - int cind = parseHeader(kdesc_file, kdesc); - if (K.size_s() < cind) { - ui->spinSize->setValue(cind); - ui->spinSize->setStyleSheet("background-color: rgb(220, 220, 255);"); - } - bool move = false; - if (ask_move) - move = (QMessageBox::question(this, "KX Pult", "Save values at associated names?", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes); - updateTree(move); -} - - -void KX_Pult::updateCDesc() { - parseHeader(cdesc_file, cdesc); - updateCommands(); -} - - -bool stringComp(const QString & s1, const QString & s2) { - if (s1.size() != s2.size()) - return s1.size() > s2.size(); - return s1 > s2; -} - - -void KX_Pult::updateTree(bool move) { - int sp = ui->treeK->verticalScrollBar()->value(); - QApplication::setOverrideCursor(Qt::WaitCursor); - //qDebug() << "fill tree ..."; - QMap prev_val; - if (move) { - for (int i = 0; i < ui->treeK->topLevelItemCount(); ++i) { - QTreeWidgetItem * ti = ui->treeK->topLevelItem(i); - if (!ti->text(1).isEmpty()) - prev_val[ti->text(1)] = ti->text(2); - } - } - ui->treeK->clear(); - ui->treeK->setUpdatesEnabled(false); - eval.clearCustomVariables(); - for (int i = 0; i < K.size_s(); ++i) { - QTreeWidgetItem * ti = new QTreeWidgetItem(); - KDesc kd = kdesc[i]; - QString kn = QString("k%1").arg(i); - knames[kn] = i; - knames_sort << kn; - if (eval.content.findVariable(kn) < 0) - eval.content.addVariable(kn, 0., false); - if (!kd.name.isEmpty()) { - knames[kd.name] = i; - knames_sort << kd.name; - eval.content.addVariable(kd.name, 0., false); - } - if (move && !kd.name.isEmpty()) { - if (prev_val.contains(kd.name)) - coeffs.setFormula(i, Q2PIString(prev_val[kd.name])); - } - ti->setText(0, QString::number(i)); - ti->setText(1, kd.name); - ti->setText(2, PI2QString(coeffs.formula(i))); - ti->setText(3, QString::number(K[i])); - ti->setText(4, typeName(kd.type)); - ti->setText(5, kd.comment); - ui->treeK->addTopLevelItem(ti); - } - eval.content.sortVariables(); - //qDebug() << "fill tree ok"; - //qDebug() << "sort ..."; - qSort(knames_sort.begin(), knames_sort.end(), stringComp); - //qDebug() << "names" << knames_sort; - //qDebug() << "sort ok"; - QApplication::restoreOverrideCursor(); - ui->treeK->setUpdatesEnabled(true); - ui->treeK->verticalScrollBar()->setValue(sp); - calculate(); - filterTree(); -} - - -void KX_Pult::updateCommands() { - while (ui->layoutCommands->count() > 0) - delete ui->layoutCommands->itemAt(0)->widget(); - QMapIterator it(cdesc); - while (it.hasNext()) { - it.next(); - KDesc kd = it.value(); - QPushButton * b = new QPushButton(); - QString text = kd.name; - if (!kd.comment.isEmpty()) - text += QString("\n(%1)").arg(kd.comment); - b->setText(text); - b->setProperty("_command", kd.index); - connect(b, SIGNAL(clicked()), this, SLOT(commandClicked())); - ui->layoutCommands->addWidget(b); - } -} - - -void KX_Pult::filterTree() { - bool he = ui->checkKHideEmpty->isChecked(); - bool hn = ui->checkKHideNormal->isChecked(); - bool hs = ui->checkKHideExpressions->isChecked(); - bool ok = false; - QString fl = ui->lineKSearch->text(); - int lc = ui->treeK->topLevelItemCount(); - for (int i = 0; i < lc; ++i) { - QTreeWidgetItem * ti = ui->treeK->topLevelItem(i); - if (ti->text(1).isEmpty() && he) - ti->setHidden(true); - else - if (fl.isEmpty()) - ti->setHidden(false); - else - ti->setHidden(!ti->text(0).contains(fl, Qt::CaseInsensitive) && - !ti->text(1).contains(fl, Qt::CaseInsensitive) && - !ti->text(2).contains(fl, Qt::CaseInsensitive) && - !ti->text(3).contains(fl, Qt::CaseInsensitive) && - !ti->text(4).contains(fl, Qt::CaseInsensitive)); - if (hn) - if (ti->data(0, Qt::UserRole).toBool()) - ti->setHidden(true); - if (hs) { - ti->data(2, Qt::DisplayRole).toDouble(&ok); - if (!ok) - ti->setHidden(true); - } - } -} - - -void KX_Pult::calculate() { - calculated.clear(); - ui->treeK->setUpdatesEnabled(false); - ui->treeK->blockSignals(true); - QApplication::setOverrideCursor(Qt::WaitCursor); - progress(0, 100); - ui->buttonCalculate->setEnabled(false); - QApplication::processEvents(); - for (int i = 0; i < K.size_s(); ++i) { - ui->treeK->topLevelItem(i)->setToolTip(2, QString()); - ui->treeK->topLevelItem(i)->setToolTip(3, QString()); - } - for (int i = 0; i < K.size_s(); ++i) { - progress(i, K.size_s()); - calculateExpression(i, QVector()); - } - ui->buttonCalculate->setEnabled(true); - ui->progress->setValue(100); - QApplication::restoreOverrideCursor(); - ui->treeK->blockSignals(false); - ui->treeK->setUpdatesEnabled(true); -} - - -bool KX_Pult::calculateExpression(int i, QVector trace) { - if (calculated.contains(i)) return true; - trace << i; - QTreeWidgetItem * ti = ui->treeK->topLevelItem(i); - QString expr = ti->text(2); - if (expr.isEmpty() || expr == "0" || expr == "0,00000000" || expr == "0.00000000") { - markNormal(ti); - calculated << i; - K[i] = 0.; - ti->setText(3, "0"); - return true; - } - //ti->setToolTip(2, QString()); - if (!eval.check(expr)) { - markError(ti, eval.error()); - return false; - } - foreach (const QString & n, knames_sort) { - if (expr.contains(n)) { - int ki = knames.value(n, -1); - if (trace.contains(ki)) { - QString strace; - trace << ki; - for (int j = 0; j < trace.size(); ++j) { - //calculated << trace[j]; - if (j > 0) strace += " -> "; - strace += "k" + QString::number(trace[j]); - } - for (int j = 0; j < trace.size(); ++j) { - QTreeWidgetItem * pti = ui->treeK->topLevelItem(trace[j]); - markError(pti, QString("Circular dependency: %1!").arg(strace)); - } - return false; - } - if (ki < 0) { - markError(ti); - return false; - } - if (calculated.contains(ki)) { - eval.setVariable(n, K[ki]); - } else { - if (calculateExpression(ki, trace)) - eval.setVariable(n, K[ki]); - else { - markError(ti); - return false; - } - } - } - } - markNormal(ti); - calculated << i; - complexd ret = eval.evaluate(); - K[i] = ret.real(); - ti->setText(3, QString::number(K[i])); - return true; -} - - -void KX_Pult::markError(QTreeWidgetItem * item, const QString & tool_tip) { - int cc = item->columnCount(); - for (int i = 0; i < cc; ++i) - item->setBackgroundColor(i, QColor(255, 200, 200)); - if (item->toolTip(2).isEmpty()) - item->setToolTip(2, tool_tip); - if (item->toolTip(3).isEmpty()) - item->setToolTip(3, tool_tip); - item->setData(0, Qt::UserRole, false); - item->setText(3, "Error"); -} - - -void KX_Pult::markNormal(QTreeWidgetItem * item) { - int cc = item->columnCount(); - for (int i = 0; i < cc; ++i) - item->setBackground(i, Qt::NoBrush); - item->setToolTip(2, QString()); - item->setToolTip(3, QString()); - item->setData(0, Qt::UserRole, true); -} - - -void KX_Pult::progress(int val, int max) { - if (ctm.elapsed() < 50) return; - ctm.restart(); - ui->progress->setValue(qRound(val * 100. / max)); - QApplication::processEvents(); -} - - -void KX_Pult::renew(bool write) { - addToList(trUtf8("Update settings from \"%1\"").arg(PI2QString(config_)), Qt::darkMagenta); - dir.setPath(config.getValue("x.output_dir", "./Experiments/").stringValue()); - setWindowTitle(config.getValue("title", "Noname").stringValue() + trUtf8(" - KX Pult")); - //if (write) ui->configWidget->write(); - if (prot_x != 0) { - prot_x->stop(); - delete prot_x; - } - if (prot_c != 0) { - prot_c->stop(); - delete prot_c; - } - prot_x = new __KX_Protocol_X(config_, name_x); - prot_c = new __KX_Protocol_C(config_, name_c); - ui->graphic->setAutoXIncrement(prot_x->expectedFrequency() > 0. ? 1. / prot_x->expectedFrequency() : 1.); - coeffs.renew(); - CONNECT1(void, bool, prot_x, received, this, received); -} - - -void KX_Pult::toggledX(int index, bool on) { - ui->graphic->setGraphicVisible(on, index); -} - - -void KX_Pult::changedX(int index, int num) { - prot_x->to_x.x_num[index] = num; -} - - -void KX_Pult::commandClicked() { - QPushButton * b = qobject_cast(sender()); - if (!b) return; - prot_c->sendCommand(b->property("_command").toInt()); -} diff --git a/kx_utils/kx_pult.h b/kx_utils/kx_pult.h deleted file mode 100644 index 2e2d21b..0000000 --- a/kx_utils/kx_pult.h +++ /dev/null @@ -1,170 +0,0 @@ -#ifndef KX_PULT_H -#define KX_PULT_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "kx_coeffs.h" -#include "kx_protocol_x.h" -#include "kx_protocol_c.h" -#include "piqt.h" -#include "session_manager.h" -#include "qpievaluator.h" - - -class XCheck: public QWidget { - Q_OBJECT -public: - explicit XCheck(int index); - QCheckBox check; - QSpinBox spin; -private: - bool eventFilter(QObject * o, QEvent * e); - int index_; -private slots: - void spinChanged(int value) {check.setChecked(true); emit valueChanged(index_, value);} - void checkChanged_(bool value) {emit checkChanged(index_, value);} -signals: - void valueChanged(int index, int value); - void checkChanged(int index, bool on); -}; - - -namespace Ui { - class KX_Pult; -}; - -class KX_Pult: public QMainWindow, public PIObject -{ - Q_OBJECT - PIOBJECT(KX_Pult) -public: - KX_Pult(); - ~KX_Pult(); - -private: - struct KDesc { - KDesc() {index = -1;} - int index; - QString name; - QString type; - QString comment; - QString value; - }; - - bool eventFilter(QObject * o, QEvent * e); - void timerEvent(QTimerEvent * ); - void setControlsEnable(bool enable); - void setX(const KX_X_Data & data); - void addToList(const QString & s, const QColor & c); - QString getNewFileName(int inc); - QColor invertColor(QColor col) {return QColor(255 - col.red(), 255 - col.green(), 255 - col.blue());} - void stopWait(); - bool calculateExpression(int i, QVector trace); - void markError(QTreeWidgetItem * item, const QString & tool_tip = QString()); - void markNormal(QTreeWidgetItem * item); - void progress(int val, int max); - void clearSelected(); - QString typeName(const QString & n) const; - int parseHeader(const QString & file, QMap & map); - - EVENT_HANDLER1(void, received, bool, ok); - EVENT_HANDLER(void, pip_sendFailed) {emit q_k_sendFailed();} - EVENT_HANDLER(void, pip_sendSucceed) {emit q_k_sendSucceed();} - EVENT_HANDLER(void, pip_receiveFailed) {emit q_k_receiveFailed();} - EVENT_HANDLER(void, pip_receiveSucceed) {emit q_k_receiveSucceed();} - - QVector checks; - QVector values; - - Ui::KX_Pult * ui; - PIString config_, name_x, name_c; - QDir dir; - QString outdir, kdesc_file, cdesc_file; - QFile file; - QTime tm, ctm; - QIcon icon_record, icon_stop; - QTextStream stream; - QTimer timer_diag; - QMap kdesc, cdesc; - QMap knames; - QSet calculated; - QStringList knames_sort; - QPIEvaluator eval; - SessionManager session; - QPIConfig config; - QMenu log_menu; - //QVector k, x; - KX_Coefficients coeffs; - __KX_Protocol_X * prot_x; - __KX_Protocol_C * prot_c; - int csize, wcnt, timer, timer_update, clear_target; - bool needWrite, isPause, need_update, show_x; - -private slots: - void loading(QPIConfig & conf); - void saving(QPIConfig & conf); - void updateGraph(); - void updateDiag(); - void updateKDesc(bool ask_move = false); - void updateCDesc(); - void updateTree(bool move = false); - void updateCommands(); - void filterTree(); - void calculate(); - void renew(bool write = true); - void toggledX(int index, bool on); - void changedX(int index, int num); - void commandClicked(); - void k_sendFailed(); - void k_sendSucceed(); - void k_receiveFailed(); - void k_receiveSucceed(); - void on_spinBuffer_editingFinished(); - void on_buttonSendK_clicked(); - void on_buttonReceiveK_clicked(); - void on_buttonShowAll_clicked(); - void on_buttonHideAll_clicked(); - void on_buttonRead_clicked(); - void on_buttonWrite_clicked(); - void on_buttonResize_clicked(); - void on_buttonSetKDesc_clicked(); - void on_buttonReparseKDesc_clicked() {updateKDesc(true);} - void on_buttonSetCDesc_clicked(); - void on_buttonReparseCDesc_clicked() {updateCDesc();} - void on_buttonCalculate_clicked() {calculate();} - void on_buttonApply_clicked() {renew();} - void on_spinSize_valueChanged(int); - void on_buttonPause_toggled(bool on) {isPause = on;} - void on_buttonRecord_clicked(); - void on_treeK_itemClicked(QTreeWidgetItem * item, int column); - void on_treeK_itemChanged(QTreeWidgetItem * item, int column); - void on_actionClear_triggered(); - -signals: - void q_k_sendFailed(); - void q_k_sendSucceed(); - void q_k_receiveFailed(); - void q_k_receiveSucceed(); - void recordStarted(const QString & fileName); - void recordStopped(const QString & fileName); - -}; - -#endif // KX_PULT_H - diff --git a/kx_utils/kx_pult.qrc b/kx_utils/kx_pult.qrc deleted file mode 100644 index 99f4688..0000000 --- a/kx_utils/kx_pult.qrc +++ /dev/null @@ -1,40 +0,0 @@ - - - icons/dialog-close.png - icons/edit-clear-.png - icons/edit-guides.png - icons/view-grid.png - icons/zoom-fit-best.png - icons/configure.png - icons/alpha.png - icons/document-save.png - icons/edit-clear-locationbar-rtl.png - icons/edit-find.png - icons/list-add.png - icons/edit-delete.png - icons/item-add.png - icons/item.png - icons/node-add.png - icons/node.png - icons/edit-copy.png - icons/edit-paste.png - icons/expand_s_x.png - icons/expand_s_y.png - icons/expand_x.png - icons/expand_y.png - icons/media-playback-pause.png - icons/media-playback-stop.png - icons/media-record.png - icons/application-exit.png - icons/document-save-.png - icons/view-refresh.png - icons/document-open.png - icons/archive-extract.png - icons/document-export.png - icons/document-import.png - icons/zoom-fit-height.png - icons/layer-visible-off.png - icons/layer-visible-on.png - icons/accessories-calculator.png - - diff --git a/kx_utils/kx_pult.ui b/kx_utils/kx_pult.ui deleted file mode 100644 index ab30c52..0000000 --- a/kx_utils/kx_pult.ui +++ /dev/null @@ -1,1311 +0,0 @@ - - - KX_Pult - - - - 0 - 0 - 1759 - 852 - - - - KX Pult - - - - - - - 0 - - - - Coefficients (K) - - - - - - - - Reparse K desc - - - - :/icons/view-refresh.png:/icons/view-refresh.png - - - - - - - Resize - - - - :/icons/zoom-fit-height.png:/icons/zoom-fit-height.png - - - - - - - Read file K - - - - :/icons/archive-extract.png:/icons/archive-extract.png - - - - - - - Send - - - - :/icons/document-export.png:/icons/document-export.png - - - - - - - Write file K - - - - :/icons/document-save-.png:/icons/document-save-.png - - - - - - - - 0 - 0 - - - - Qt::CustomContextMenu - - - QAbstractItemView::NoEditTriggers - - - QAbstractItemView::NoSelection - - - QAbstractItemView::ScrollPerPixel - - - QAbstractItemView::ScrollPerPixel - - - - - - - Receive - - - - :/icons/document-import.png:/icons/document-import.png - - - - - - - Set K desc file ... - - - - :/icons/document-open.png:/icons/document-open.png - - - - - - - 65536 - - - - - - - - 0 - 0 - - - - - 200 - 0 - - - - - - - - - - - - - - - Hide empty - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 20 - 20 - - - - - - - - Hide expressions - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 20 - 20 - - - - - - - - Hide without errors - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 20 - 20 - - - - - - - - :/icons/edit-find.png - - - true - - - Qt::AlignCenter - - - - - - - Search: - - - - - - - - 0 - 0 - - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 40 - 20 - - - - - - - - Auto calculate - - - true - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 20 - 20 - - - - - - - - Calculate - - - Calculate - - - - :/icons/accessories-calculator.png:/icons/accessories-calculator.png - - - - - - - 100 - - - Calculate %p% - - - - - - - - - Qt::CustomContextMenu - - - QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed - - - true - - - QAbstractItemView::ExtendedSelection - - - QAbstractItemView::ScrollPerPixel - - - QAbstractItemView::ScrollPerPixel - - - false - - - false - - - 6 - - - 200 - - - 20 - - - - Index - - - - - Name - - - - - Expression - - - - - Calculated - - - - - Type - - - - - Comment - - - - - - - - - Commands (C) - - - - - - - - Set C desc file ... - - - - :/icons/document-open.png:/icons/document-open.png - - - - - - - Reparse C desc - - - - :/icons/view-refresh.png:/icons/view-refresh.png - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - Commands - - - - - - QFrame::NoFrame - - - true - - - - - 0 - 0 - 1370 - 655 - - - - - 0 - - - 0 - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 66 - 441 - - - - - - - - - - - - - - - - - - Graphics (X) - - - - - - - 10 - - - - - - - - - - - 0 - 0 - - - - Show all - - - - :/icons/layer-visible-on.png:/icons/layer-visible-on.png - - - - - - - - 0 - 0 - - - - Hide all - - - - :/icons/layer-visible-off.png:/icons/layer-visible-off.png - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Start record - - - - :/icons/media-record.png:/icons/media-record.png - - - - - - - - - - - Pause - - - - :/icons/media-playback-pause.png:/icons/media-playback-pause.png - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Show - - - - - - - - 0 - 0 - - - - с - - - 1 - - - 0.100000000000000 - - - 9999.000000000000000 - - - 10.000000000000000 - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 40 - 20 - - - - - - - - Save - - - - - - - - 0 - 0 - - - - с - - - 1 - - - 0.100000000000000 - - - 9999.000000000000000 - - - 60.000000000000000 - - - - - - - - - Graphic::Autofit|Graphic::BorderInputs|Graphic::Clear|Graphic::Configure|Graphic::CursorAxis|Graphic::Grid|Graphic::OnlyExpandX|Graphic::OnlyExpandY|Graphic::Save - - - false - - - false - - - 60.000000000000000 - - - 10.000000000000000 - - - - - - - - Configuration - - - - - - K - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - receiver: - - - - - - - - - - - - - - sender: - - - - - - - - - - - - - - sended count: - - - - - - - true - - - 0 - - - 1999999999 - - - - - - - received count: - - - - - - - true - - - 0 - - - 1999999999 - - - - - - - wrong received count: - - - - - - - true - - - 0 - - - 1999999999 - - - - - - - type: - - - - - - - - - - - - - - address K: - - - - - - - - - - - - - - - - - - - - - missed received count: - - - - - - - true - - - 0 - - - 1999999999 - - - - - - - address pult: - - - - - - - - - - X - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - receiver: - - - - - - - - - - - - - - sender: - - - - - - - - - - - - - - type: - - - - - - - - - - - - - - address X: - - - - - - - address pult: - - - - - - - - - - - - - - sended count: - - - - - - - true - - - 0 - - - 1999999999 - - - - - - - received count: - - - - - - - true - - - 0 - - - 1999999999 - - - - - - - wrong received count: - - - - - - - true - - - 0 - - - 1999999999 - - - - - - - - - - - - - - missed received count: - - - - - - - true - - - 0 - - - 1999999999 - - - - - - - - - - C - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - receiver: - - - - - - - - - - - - - - sender: - - - - - - - - - - - - - - type: - - - - - - - - - - - - - - address C: - - - - - - - address pult: - - - - - - - - - - - - - - sended count: - - - - - - - true - - - 0 - - - 1999999999 - - - - - - - received count: - - - - - - - true - - - 0 - - - 1999999999 - - - - - - - wrong received count: - - - - - - - true - - - 0 - - - 1999999999 - - - - - - - - - - - - - - missed received count: - - - - - - - true - - - 0 - - - 1999999999 - - - - - - - - - - - - true - - - true - - - true - - - false - - - 20 - - - - - - - Apply - - - - :/icons/document-save-.png:/icons/document-save-.png - - - - - - - - - - - - - - - :/icons/edit-clear-.png:/icons/edit-clear-.png - - - Clear - - - - - - Graphic - QFrame -
graphic.h
-
- - CLineEdit - QLineEdit -
clineedit.h
-
- - QPIConfigWidget - QTreeWidget -
qpiconfigwidget.h
-
-
- - - - - - spinHistory - valueChanged(double) - graphic - setMaxVisibleTime(double) - - - 919 - 107 - - - 932 - 132 - - - - -
diff --git a/kx_utils/main_kx_pult.cpp b/kx_utils/main_kx_pult.cpp deleted file mode 100644 index e5c1786..0000000 --- a/kx_utils/main_kx_pult.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "kx_pult.h" - - -int main(int argc, char *argv[]) { - QApplication a(argc, argv); - KX_Pult w; - w.show(); - return a.exec(); -} diff --git a/kx_utils/make_lib.bat b/kx_utils/make_lib.bat deleted file mode 100644 index 0148a43..0000000 --- a/kx_utils/make_lib.bat +++ /dev/null @@ -1 +0,0 @@ -cmake -G "MinGW Makefiles" -DLIB=1 && make install . %* diff --git a/kx_utils/piprotocol.cpp b/kx_utils/piprotocol.cpp deleted file mode 100644 index 9b9f048..0000000 --- a/kx_utils/piprotocol.cpp +++ /dev/null @@ -1,718 +0,0 @@ -/* - PIP - Platform Independent Primitives - Protocol, input/output channel (COM, UDP) - Copyright (C) 2020 Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "piprotocol.h" - -/** \class PIProtocol - * \brief - * \details - * \section PIProtocol_sec0 Synopsis - * - * - * - * */ - - /// DEPRECATED -PIProtocol::PIProtocol(const PIString & config, const PIString & name_, void * recHeaderPtr, int recHeaderSize, void * recDataPtr, int recDataSize, void * sendDataPtr_, int sendDataSize_): PIObject() { - init(); - protName = name_; - PIObject::setName(name_); - PIConfig conf(config, PIIODevice::ReadOnly); - if (!conf.isOpened()) { - piCoutObj << "Can`t open \"" << config << "\"!"; - devReceiverState = devSenderState = "Config error"; - return; - } - PIConfig::Entry & b(conf.getValue(name_)), - & rb(b.getValue("receiver")), - & sb(b.getValue("sender")); - - init_receiver(b, rb, config); - init_sender(b, sb, config); - - headerPtr = (uchar * )recHeaderPtr; - headerSize = recHeaderSize; - dataPtr = (uchar * )recDataPtr; - dataSize = recDataSize; - sendDataPtr = (uchar * )sendDataPtr_; - sendDataSize = sendDataSize_; - packet_ext->setHeader(PIByteArray(recHeaderPtr, recHeaderSize)); - packet_ext->setPayloadSize(recDataSize); - packet_ext->setPacketSize(recDataSize); - packet_ext->setSplitMode(PIPacketExtractor::Header); - bool null_h = (recHeaderPtr == 0 || recHeaderSize == 0), null_d = (recDataPtr == 0 || recDataSize == 0); - if (null_h && null_d) packet_ext->setSplitMode(PIPacketExtractor::None); - else { - if (null_h) packet_ext->setSplitMode(PIPacketExtractor::Size); - } -} - - -PIProtocol::~PIProtocol() { - delete diagTimer; - delete sendTimer; - delete secTimer; - delete packet_ext; - if (eth != 0) delete eth; - if (ser != 0) delete ser; -} - - -void PIProtocol::init() { - packet_ext = new PIPacketExtractor(0, PIPacketExtractor::None); - packet_ext->setThreadedReadData(this); - packet_ext->setThreadedReadSlot(receiveEvent); - packet_ext->setHeaderCheckSlot(headerValidateEvent); - packet_ext->setName("__S__PIProtocol::packet_ext"); - work = new_mp_prot = false; - eth = 0; - ser = 0; - ret_func = 0; - mp_owner = 0; - net_diag = PIProtocol::Unknown; - cur_pckt = 0; - packets[0] = packets[1] = pckt_cnt = pckt_cnt_max = 0; - diagTimer = 0; - timeout_ = 3.f; - sendTimer = new PITimer(sendEvent, this); - diagTimer = new PITimer(diagEvent, this); - secTimer = new PITimer(secEvent, this); - sendTimer->setName("__S__PIProtocol::sendTimer"); - diagTimer->setName("__S__PIProtocol::diagTimer"); - secTimer->setName("__S__PIProtocol::secTimer"); - wrong_count = receive_count = send_count = missed_count = 0; - packets_in_sec = packets_out_sec = bytes_in_sec = bytes_out_sec = 0; - immediate_freq = integral_freq = ifreq = 0.f; - headerPtr = dataPtr = sendDataPtr = 0; - headerSize = dataSize = sendDataSize = 0; - type_rec = type_send = PIProtocol::None; - devSenderState = devReceiverState = "Unknown"; - devSenderName = devReceiverName = "no device"; - secTimer->start(1000.); - /*addEvent("receiver started"); - addEvent("receiver stopped"); - addEvent("sender started"); - addEvent("sender stopped"); - addEvent("received"); - addEvent("quality changed"); - addEventHandler(HANDLER(PIProtocol, startReceive)); - addEventHandler(HANDLER(PIProtocol, startSend)); - addEventHandler(HANDLER(PIProtocol, start)); - addEventHandler(HANDLER(PIProtocol, stopReceive)); - addEventHandler(HANDLER(PIProtocol, stopSend)); - addEventHandler(HANDLER(PIProtocol, stop));*/ -} - - -void PIProtocol::init_sender(PIConfig::Entry & b, PIConfig::Entry & sb, const PIString & config) { - int ps, gps; - bool ok, gok, flag, gflag, has_dev = false; - float freq, gfreq; - PIFlags pp(0); - PIString dev, gdev; - - if (sb.isEntryExists("ip") && sb.isEntryExists("device")) { - piCoutObj << "Ambiguous sender type in \"" << config << "\"!"; - devSenderState = "Config error"; - return; - } - dev = sb.getValue("ip", "", &ok); - gdev = b.getValue("ip", "", &gok); - has_dev = false; - if (ok || gok) { - if (gok && !ok) dev = gdev; - if (gok && ok && (dev != gdev)) { - piCoutObj << "Ambiguous sender type in \"" << config << "\"!"; - devSenderState = "Config error"; - return; - } - ps = sb.getValue("port", 0, &ok); - gps = b.getValue("port", 0, &gok); - if (ok || gok) { - if (gok && !ok) ps = gps; - if (gok && ok && (ps != gps)) { - piCoutObj << "Ambiguous send port in \"" << config << "\"!"; - devSenderState = "Config error"; - return; - } - type_send = PIProtocol::Ethernet; - if (eth == 0) eth = new PIEthernet(); - eth->setName("__S__PIProtocol::eth"); - setSenderAddress(dev, ps); - //setReceiverAddress(dev, ps); - has_dev = true; - flag = sb.getValue("reconnectEnabled", true, &ok); - gflag = b.getValue("reconnectEnabled", true, &gok); - if (ok || gok) { - if (gok && !ok) flag = gflag; - if (gok && ok && (flag != gflag)) { - piCoutObj << "Ambiguous \"reconnectEnabled\" flag in \"" << config << "\"!"; - devReceiverState = "Config error"; - return; - } - eth->setReopenEnabled(flag); - } - freq = sb.getValue("reconnectTimeout", 1., &ok); - gfreq = b.getValue("reconnectTimeout", 1., &gok); - if (ok || gok) { - if (gok && !ok) freq = gfreq; - if (gok && ok && (freq != gfreq)) { - piCoutObj << "Ambiguous \"reconnectTimeout\" value in \"" << config << "\"!"; - devReceiverState = "Config error"; - return; - } - eth->setReopenTimeout(freq * 1000); - } - /*if (sendDataPtr_ == 0) - piCoutObj << "Warning: null send data pointer!"; - if (sendDataSize_ == 0) - piCoutObj << "Warning: null send data size!";*/ - } else { - piCoutObj << "Can`t find \"" << name() << ".sender.port\" or \"" << name() << ".port\" in \"" << config << "\"!"; - devSenderState = "Config error"; - return; - } - } - dev = sb.getValue("device", "", &ok); - gdev = b.getValue("device", "", &gok); - if (ok || gok) { - if (gok && !ok) dev = gdev; - if (gok && ok && (dev != gdev)) { - piCoutObj << "Ambiguous sender type in \"" << config << "\"!"; - devSenderState = "Config error"; - return; - } - ps = sb.getValue("speed", 0, &ok); - gps = b.getValue("speed", 0, &gok); - if (ok || gok) { - if (gok && !ok) ps = gps; - if (gok && ok && (ps != gps)) { - piCoutObj << "Ambiguous send \"speed\" in \"" << config << "\"!"; - devSenderState = "Config error"; - return; - } - flag = sb.getValue("parity", false, &ok); - gflag = b.getValue("parity", false, &gok); - if (ok || gok) { - if (gok && !ok) flag = gflag; - if (gok && ok && (flag != gflag)) { - piCoutObj << "Ambiguous send \"parity\" in \"" << config << "\"!"; - devSenderState = "Config error"; - return; - } - pp.setFlag(PISerial::ParityControl, flag); - } - flag = sb.getValue("twoStopBits", false, &ok); - gflag = b.getValue("twoStopBits", false, &gok); - if (ok || gok) { - if (gok && !ok) flag = gflag; - if (gok && ok && (flag != gflag)) { - piCoutObj << "Ambiguous send \"twoStopBits\" parity in \"" << config << "\"!"; - devSenderState = "Config error"; - return; - } - pp.setFlag(PISerial::TwoStopBits, flag); - } - } else { - piCoutObj << "Can`t find \"" << name() << ".sender.speed\" or \"" << name() << ".speed\" in \"" << config << "\"!"; - devSenderState = "Config error"; - return; - } - type_send = PIProtocol::Serial; - if (ser == 0) ser = new PISerial(dev); - ser->setName("__S__PIProtocol::ser"); - setSenderDevice(dev, (PISerial::Speed)ps); - ser->setOutSpeed((PISerial::Speed)ps); - ser->setParameters(pp); - has_dev = true; - /*if (sendDataPtr_ == 0) - piCoutObj << "Warning: null send data pointer!"; - if (sendDataSize_ == 0) - piCoutObj << "Warning: null send data size!";*/ - } - freq = sb.getValue("frequency", -1.f, &ok); - gfreq = b.getValue("frequency", -1.f, &gok); - if (gok && !ok) freq = gfreq; - if (gok && ok && (freq != gfreq)) { - piCoutObj << "Ambiguous sender frequency in \"" << config << "\"!"; - devSenderState = "Config error"; - return; - } - if (freq > 0.f && !has_dev) - piCoutObj << "Warning: no sender device and not null send frequency!"; - setSenderFrequency(freq); -} - - -void PIProtocol::init_receiver(PIConfig::Entry & b, PIConfig::Entry & rb, const PIString & config) { - int ps, gps; - bool ok, gok, flag, gflag, has_dev = false; - float freq, gfreq; - PIFlags pp(0); - PIString dev, gdev; - - if (rb.isEntryExists("ip") && rb.isEntryExists("device")) { - piCoutObj << "Ambiguous receiver type in \"" << config << "\"!"; - devReceiverState = "Config error"; - return; - } - dev = rb.getValue("ip", "", &ok); - gdev = b.getValue("ip", "", &gok); - if (ok || gok) { - if (gok && !ok) dev = gdev; - if (gok && ok && (dev != gdev)) { - piCoutObj << "Ambiguous receiver type in \"" << config << "\"!"; - devReceiverState = "Config error"; - return; - } - ps = rb.getValue("port", 0, &ok); - gps = b.getValue("port", 0, &gok); - if (ok || gok) { - if (gok && !ok) ps = gps; - if (gok && ok && (ps != gps)) { - piCoutObj << "Ambiguous receive port in \"" << config << "\"!"; - devReceiverState = "Config error"; - return; - } - type_rec = PIProtocol::Ethernet; - eth = new PIEthernet(); - eth->setName("__S__PIProtocol::eth"); - packet_ext->setDevice(eth); - //setSenderAddress(dev, ps); - setReceiverAddress(dev, ps); - has_dev = true; - flag = rb.getValue("reconnectEnabled", true, &ok); - gflag = b.getValue("reconnectEnabled", true, &gok); - if (ok || gok) { - if (gok && !ok) flag = gflag; - if (gok && ok && (flag != gflag)) { - piCoutObj << "Ambiguous \"reconnectEnabled\" flag in \"" << config << "\"!"; - devReceiverState = "Config error"; - return; - } - eth->setReopenEnabled(flag); - } - freq = rb.getValue("reconnectTimeout", 1., &ok); - gfreq = b.getValue("reconnectTimeout", 1., &gok); - if (ok || gok) { - if (gok && !ok) freq = gfreq; - if (gok && ok && (freq != gfreq)) { - piCoutObj << "Ambiguous \"reconnectTimeout\" value in \"" << config << "\"!"; - devReceiverState = "Config error"; - return; - } - eth->setReopenTimeout(freq * 1000); - } - /*if (recDataPtr == 0) - piCoutObj << "Warning: null receive data pointer!"; - if (recDataSize == 0) - piCoutObj << "Warning: null receive data size!";*/ - } else { - piCoutObj << "Can`t find \"" << name() << ".receiver.port\" or \"" << name() << ".port\" in \"" << config << "\"!"; - devReceiverState = "Config error"; - return; - } - } - dev = rb.getValue("device", "", &ok); - gdev = b.getValue("device", "", &gok); - if (ok || gok) { - if (gok && !ok) dev = gdev; - if (gok && ok && (dev != gdev)) { - piCoutObj << "Ambiguous receiver type in \"" << config << "\"!"; - devReceiverState = "Config error"; - return; - } - ps = rb.getValue("speed", 0, &ok); - gps = b.getValue("speed", 0, &gok); - if (ok || gok) { - if (gok && !ok) ps = gps; - if (gok && ok && (ps != gps)) { - piCoutObj << "Ambiguous receive \"speed\" in \"" << config << "\"!"; - devReceiverState = "Config error"; - return; - } - flag = rb.getValue("parity", false, &ok); - gflag = b.getValue("parity", false, &gok); - if (ok || gok) { - if (gok && !ok) flag = gflag; - if (gok && ok && (flag != gflag)) { - piCoutObj << "Ambiguous receive \"parity\" in \"" << config << "\"!"; - devReceiverState = "Config error"; - return; - } - pp.setFlag(PISerial::ParityControl, flag); - } - flag = rb.getValue("twoStopBits", false, &ok); - gflag = b.getValue("twoStopBits", false, &gok); - if (ok || gok) { - if (gok && !ok) flag = gflag; - if (gok && ok && (flag != gflag)) { - piCoutObj << "Ambiguous receive \"twoStopBits\" parity in \"" << config << "\"!"; - devReceiverState = "Config error"; - return; - } - pp.setFlag(PISerial::TwoStopBits, flag); - } - type_rec = PIProtocol::Serial; - type_send = PIProtocol::Serial; - ser = new PISerial(dev); - ser->setName("__S__PIProtocol::ser"); - packet_ext->setDevice(ser); - //setSenderDevice(dev, (PISerial::Speed)ps); - setReceiverDevice(dev, (PISerial::Speed)ps); - ser->setInSpeed((PISerial::Speed)ps); - ser->setParameters(pp); - ps = rb.getValue("vtime", 1, &ok); - gps = b.getValue("vtime", 1, &gok); - if (ok || gok) { - if (gok && !ok) ps = gps; - if (gok && ok && (ps != gps)) { - piCoutObj << "Ambiguous receive \"vtime\" in \"" << config << "\"!"; - devReceiverState = "Config error"; - return; - } - ser->setVTime(ps); - } - has_dev = true; - /*if (recDataPtr == 0) - piCoutObj << "Warning: null receive data pointer!"; - if (recDataSize == 0) - piCoutObj << "Warning: null receive data size!";*/ - } else { - piCoutObj << "Can`t find \"" << name() << ".receiver.speed\" or \"" << name() << ".speed\" in \"" << config << "\"!"; - devReceiverState = "Config error"; - return; - } - } - freq = rb.getValue("frequency", -1.f, &ok); - gfreq = b.getValue("frequency", -1.f, &gok); - if (gok && !ok) freq = gfreq; - if (gok && ok && (freq != gfreq)) { - piCoutObj << "Ambiguous expected frequency in \"" << config << "\"!"; - devReceiverState = "Config error"; - return; - } - if (freq > 0.f && !has_dev) - piCoutObj << "Warning: no receiver device and not null expected frequency!"; - float tm = b.getValue("disconnectTimeout", 3.f); - if (tm <= 0.f) - piCoutObj << "Warning: diconnect timeout <= 0 s!"; - timeout_ = (tm < 0.f) ? 0.f : tm; - setExpectedFrequency(freq); -} - - -void PIProtocol::setReceiverDevice(const PIString & device, PISerial::Speed speed, bool force) { - if (force) { - type_send = type_rec = PIProtocol::Serial; - if (ser == 0) { - ser = new PISerial(); - ser->setName("__S__PIProtocol::ser"); - packet_ext->setDevice(ser); - } - } - if (type_rec == PIProtocol::Serial && ser != 0) { - ser->setDevice(device); - ser->setSpeed(speed); - devReceiverName = device; - devSenderName = device; - } -} - - -void PIProtocol::setReceiverAddress(const PIString & ip, int port, bool force) { - if (force) { - type_rec = PIProtocol::Ethernet; - if (eth == 0) { - eth = new PIEthernet(); - eth->setName("__S__PIProtocol::eth"); - packet_ext->setDevice(eth); - } - } - if (type_rec == PIProtocol::Ethernet && eth != 0) { - eth->setReadAddress(ip, port); - if (ip.trimmed().isEmpty()) devReceiverName = "no ip"; - else devReceiverName = ip + ":" + PIString::fromNumber(port); - } -} - - -void PIProtocol::setSenderDevice(const PIString & device, PISerial::Speed speed, bool force) { - if (force) { - type_send = type_rec = PIProtocol::Serial; - if (ser == 0) ser = new PISerial(); - ser->setName("__S__PIProtocol::ser"); - } - if (type_send == PIProtocol::Serial && ser != 0) { - ser->setDevice(device); - ser->setSpeed(speed); - ser->open(); - devSenderName = device; - } -} - - -void PIProtocol::setSenderAddress(const PIString & ip, int port, bool force) { - if (force) { - type_send = PIProtocol::Ethernet; - if (eth == 0) eth = new PIEthernet(); - eth->setName("__S__PIProtocol::eth"); - } - if (type_send == PIProtocol::Ethernet && eth != 0) { - eth->setSendAddress(ip, port); - if (ip.isEmpty()) devSenderName = "no ip"; - else devSenderName = ip + ":" + PIString::fromNumber(port); - } -} - - -void PIProtocol::setSenderIP(const PIString & ip, bool force) { - if (force) { - type_send = PIProtocol::Ethernet; - if (eth == 0) eth = new PIEthernet(); - } - if (type_send == PIProtocol::Ethernet && eth != 0) { - eth->setSendIP(ip); - if (ip.isEmpty()) devSenderName = "no ip"; - else devSenderName = ip + ":" + PIString::fromNumber(eth->sendPort()); - } -} - - -void PIProtocol::setSenderPort(int port, bool force) { - if (force) { - type_send = PIProtocol::Ethernet; - if (eth == 0) eth = new PIEthernet(); - eth->setName("__S__PIProtocol::eth"); - } - if (type_send == PIProtocol::Ethernet && eth != 0) { - eth->setSendPort(port); - if (eth->sendIP().isEmpty()) devSenderName = "no ip"; - else devSenderName = eth->sendIP() + ":" + PIString::fromNumber(port); - } -} - - -void PIProtocol::setExpectedFrequency(float frequency) { - exp_freq = frequency; - changeDisconnectTimeout(); -} - - -void PIProtocol::changeDisconnectTimeout() { - pckt_cnt_max = int(piRound(timeout_ * exp_freq)); - if (pckt_cnt_max < 3) pckt_cnt_max = 3; - last_packets.resize(pckt_cnt_max); -} - - -void PIProtocol::startReceive(float exp_frequency) { - if (exp_frequency > 0.f) exp_freq = exp_frequency; - //if (type_rec == PIProtocol::Serial) ser->start(); - //if (type_rec == PIProtocol::Ethernet) eth->start(); - packet_ext->startThreadedRead(); - msleep(1); - check_state(); - if (exp_freq <= 0.f) return; - setExpectedFrequency(exp_freq); - diagTimer->start(1000. / exp_freq); - diag_tm.reset(); - receiverStarted(); -} - - -void PIProtocol::startSend(float frequency) { - //cout << "** start send " << send_freq << ", " << frequency << endl; - if (frequency > 0.f) send_freq = frequency; - msleep(1); - check_state(); - if (send_freq <= 0.f) return; - sendTimer->start(1000. / send_freq); - diag_tm.reset(); - senderStarted(); -} - - -void PIProtocol::stopReceive() { - //if (type_rec == PIProtocol::Serial) ser->stop(); - //if (type_rec == PIProtocol::Ethernet) eth->stop(); - packet_ext->stop(); - diagTimer->stop(); - receiverStopped(); -} - - -bool PIProtocol::receiveEvent(void * t, uchar * data, int size) { - PIProtocol * p = (PIProtocol * )t; - if (!p->receive(data, size)) return false; - p->work = true; - //p->lock(); - if (p->validate()) { - p->received(true); - //p->unlock(); - p->ifreq = p->diag_tm.elapsed_m(); - if (p->ifreq > 0.) p->ifreq = 1000. / p->ifreq; - p->diag_tm.reset(); - p->receive_count++; - p->packets_in_sec++; - p->bytes_in_sec += size; - p->cur_pckt = 1; - if (p->ret_func != 0) p->ret_func(p); - if (p->mp_owner != 0) PIMultiProtocolBase::receiveEvent(p->mp_owner, p, true, data, size); - return true; - } - p->received(false); - //p->unlock(); - p->wrong_count++; - if (p->mp_owner != 0) PIMultiProtocolBase::receiveEvent(p->mp_owner, p, false, data, size); - return false; -} - - -void PIProtocol::diagEvent(void * t, int) { - PIProtocol * p = (PIProtocol * )t; - p->calc_freq(); - p->calc_diag(); - p->check_state(); - if (p->ser != 0) p->missed_count = p->packet_ext->missedPackets(); -} - - -void PIProtocol::secEvent(void * t, int ) { - PIProtocol * p = (PIProtocol * )t; - p->speedIn = PIString::readableSize(p->bytes_in_sec) + "/s"; - p->speedOut = PIString::readableSize(p->bytes_out_sec) + "/s"; - p->bytes_in_sec = p->bytes_out_sec = p->packets_in_sec = p->packets_out_sec = 0; - if (p->ser != 0) p->missed_count = p->packet_ext->missedPackets(); -} - - -void PIProtocol::calc_diag() { - PIProtocol::Quality diag; - if (!work) { - diag = PIProtocol::Unknown; - return; - } - if (pckt_cnt < pckt_cnt_max) { - last_packets[pckt_cnt] = cur_pckt; - pckt_cnt++; - } else { - packets[(int)last_packets.back()]--; - if (!last_packets.isEmpty()) last_packets.pop_back(); - last_packets.push_front(cur_pckt); - } - packets[(int)cur_pckt]++; - cur_pckt = 0; - float good_percents; - good_percents = (float)packets[1] / pckt_cnt * 100.f; - if (good_percents == 0.f) diag = PIProtocol::Failure; - else if (good_percents <= 20.f) diag = PIProtocol::Bad; - else if (good_percents > 20.f && good_percents <= 80.f) diag = PIProtocol::Average; - else diag = PIProtocol::Good; - if (diag != net_diag) { - qualityChanged(diag, net_diag); - net_diag = diag; - } -} - - -void PIProtocol::calc_freq() { - float tf;// = float(1000.f / diagTimer->elapsed_m()); - tf = immediate_freq = ifreq; - ifreq = 0.f; - if (last_freq.size_s() >= pckt_cnt_max && last_freq.size_s() > 0) last_freq.pop_front(); - last_freq.push_back(tf); - tf = last_freq[0]; - for (uint i = 1; i < last_freq.size(); ++i) - tf += last_freq[i]; - integral_freq = tf / last_freq.size(); -} - - -void PIProtocol::check_state() { - if (type_rec == PIProtocol::Serial) { - if (ser != 0) { - if (ser->isOpened()) devReceiverState = "Opened"; - else devReceiverState = "Not opened"; - } - else devReceiverState = "Not exists"; - } - if (type_rec == PIProtocol::Ethernet) { - if (eth != 0) { - if (eth->isOpened()) devReceiverState = "Opened"; - else devReceiverState = "Not opened"; - } - else devReceiverState = "Not exists"; - } - if (type_send == PIProtocol::Serial) { - if (ser != 0) { - if (ser->isOpened()) devSenderState = "Opened"; - else devSenderState = "Not opened"; - } - else devSenderState = "Not exists"; - } - if (type_send == PIProtocol::Ethernet) { - if (eth != 0) { - if (eth->isOpened()) devSenderState = "Opened"; - else devSenderState = "Not opened"; - } - else devSenderState = "Not exists"; - } -} - - -void PIProtocol::send(const void * data, int size, bool direct) { - if (!direct) { - if (data == 0 || size == 0) return; - if (!aboutSend()) return; - } - if (type_send == PIProtocol::Serial) - if (ser->send(data, size)) { - send_count++; - packets_out_sec++; - bytes_out_sec += size; - } - if (type_send == PIProtocol::Ethernet) - if (eth->send(data, size)) { - send_count++; - packets_out_sec++; - bytes_out_sec += size; - } -} - - -void PIProtocol::send() { - //lock(); - //memcpy(packet, sendDataPtr, sendDataSize); - //unlock(); - if (!aboutSend()) return; - if (sendDataPtr == 0 || sendDataSize == 0) return; - if (type_send == PIProtocol::Serial) - if (ser->send(sendDataPtr, sendDataSize)) { - send_count++; - packets_out_sec++; - bytes_out_sec += sendDataSize; - } - if (type_send == PIProtocol::Ethernet) - if (eth->send(sendDataPtr, sendDataSize)) { - send_count++; - packets_out_sec++; - bytes_out_sec += sendDataSize; - } -} diff --git a/kx_utils/piprotocol.h b/kx_utils/piprotocol.h deleted file mode 100644 index 496d786..0000000 --- a/kx_utils/piprotocol.h +++ /dev/null @@ -1,238 +0,0 @@ -/*! \file piprotocol.h - * \brief Highly configurable from file I/O channel -*/ -/* - PIP - Platform Independent Primitives - Protocol, input/output channel (COM, UDP) - Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef PIPROTOCOL_H -#define PIPROTOCOL_H - -#include "piserial.h" -#include "piethernet.h" -#include "pipacketextractor.h" -#include "pitimer.h" -#include "piconfig.h" -#include "pifile.h" - -class PIProtocol; /// DEPRECATED - -class PIP_EXPORT PIMultiProtocolBase: protected PIObject /// DEPRECATED -{ - PIOBJECT_SUBCLASS(PIMultiProtocolBase, PIObject) - friend class PIProtocol; -public: - PIMultiProtocolBase() {;} /// DEPRECATED - virtual ~PIMultiProtocolBase() {;} - -protected: - virtual void received(PIProtocol * prot, bool corrected, uchar * data, int size) {;} - -private: - static void receiveEvent(PIMultiProtocolBase * p, PIProtocol * prot, bool corrected, uchar * data, int size) {p->mutex_receive.lock(); p->received(prot, corrected, data, size); p->mutex_receive.unlock();} - - PIMutex mutex_receive; - -}; - -typedef void (*ReceiveFunc)(void * ); - -/// events: -/// void receiverStarted() -/// void receiverStopped() -/// void senderStarted() -/// void senderStopped() -/// void received(bool validate_is_ok) -/// void qualityChanged(PIProtocol::Quality old_quality, PIProtocol::Quality new_quality) -/// -/// handlers: -/// void startReceive(float exp_frequency = -1.f) -/// void stopReceive() -/// void startSend(float frequency = -1.f) -/// void stopSend() -/// void start() -/// void stop() -/// void send() -/// void send(const void * data, int size, bool direct = false) -class PIP_EXPORT PIProtocol: public PIObject /// DEPRECATED -{ - PIOBJECT_SUBCLASS(PIProtocol, PIObject) - friend class PIMultiProtocolBase; - friend class PIMultiProtocol; - enum Type {None, Serial, Ethernet}; -public: - - //! Contructs an empty unconfigured protocol - PIProtocol(): PIObject() {init();} /// DEPRECATED - - //! Contructs protocol configured from file "config", config file section "name" - PIProtocol(const PIString & config, const PIString & name, void * recHeaderPtr = 0, int recHeaderSize = 0, - void * recDataPtr = 0, int recDataSize = 0, void * sendDataPtr = 0, int sendDataSize = 0); // from config - - virtual ~PIProtocol(); - - //! Connection quality - enum Quality { - Unknown /** Unknown, no one packet received yet */ = 1, - Failure /** No connection, no one correct packet received for last period */ = 2, - Bad /** Bad connection, correct packets received <= 20% */ = 3, - Average /** Average connection, correct packets received > 20% and <= 80% */ = 4, - Good /** Good connection, correct packets received > 80% */ = 5 - }; - - EVENT_HANDLER0(void, startReceive) {startReceive(-1.f);} - EVENT_HANDLER1(void, startReceive, float, exp_frequency); // if "frequency = -1" used last passed value - EVENT_HANDLER0(void, stopReceive); - void setExpectedFrequency(float frequency); // for connection quality diagnostic - void setReceiverDevice(const PIString & device, PISerial::Speed speed, bool force = false); // for Serial - void setReceiverData(void * dataPtr, int dataSize) {this->dataPtr = (uchar * )dataPtr; this->dataSize = dataSize; packet_ext->setHeader(PIByteArray(headerPtr, headerSize)); packet_ext->setPayloadSize(dataSize); packet_ext->setPacketSize(dataSize);} - void setReceiverDataHeader(void * headerPtr, int headerSize) {this->headerPtr = (uchar * )headerPtr; this->headerSize = headerSize; packet_ext->setHeader(PIByteArray(headerPtr, headerSize)); packet_ext->setPayloadSize(dataSize); packet_ext->setPacketSize(dataSize);} - void setReceiverAddress(const PIString & ip, int port, bool force = false); // for Ethernet - void setReceiverParameters(PIFlags parameters) {if (type_rec == PIProtocol::Serial || type_send == PIProtocol::Serial) ser->setParameters(parameters);} // for Serial - void setReceiveSlot(ReceiveFunc slot) {ret_func = slot;} - float expectedFrequency() const {return exp_freq;} - - EVENT_HANDLER0(void, startSend) {startSend(-1.f);} // if "frequency = -1" used last passed value - EVENT_HANDLER1(void, startSend, float, frequency); // if "frequency = -1" used last passed value - EVENT_HANDLER0(void, stopSend) {sendTimer->stop(); senderStopped();} - void setSenderFrequency(float frequency) {send_freq = frequency;} - void setSenderDevice(const PIString & device, PISerial::Speed speed, bool force = false); // for Serial - void setSenderData(void * dataPtr, int dataSize) {sendDataPtr = (uchar * )dataPtr; sendDataSize = dataSize;} - void setSenderAddress(const PIString & ip, int port, bool force = false); // for Ethernet - void setSenderIP(const PIString & ip, bool force = false); // for Ethernet - void setSenderPort(int port, bool force = false); // for Ethernet - void setSenderParameters(PIFlags parameters) {if (type_send == PIProtocol::Serial) ser->setParameters(parameters);} // for Serial - float senderFrequency() const {return send_freq;} - - EVENT_HANDLER0(void, start) {startReceive(); startSend();} - EVENT_HANDLER0(void, stop) {stopReceive(); stopSend();} - EVENT_HANDLER0(void, send); - EVENT_HANDLER2(void, send, const void *, data, int, size) {send(data, size, false);} - EVENT_HANDLER3(void, send, const void *, data, int, size, bool, direct); - - void setName(const PIString & name) {protName = name; PIObject::setName(name);} - PIString name() const {return protName;} - void setDisconnectTimeout(float timeout) {timeout_ = timeout; changeDisconnectTimeout();} - float disconnectTimeout() const {return timeout_;} - const float * disconnectTimeout_ptr() const {return &timeout_;} - float immediateFrequency() const {return immediate_freq;} - float integralFrequency() const {return integral_freq;} - const float * immediateFrequency_ptr() const {return &immediate_freq;} - const float * integralFrequency_ptr() const {return &integral_freq;} - ullong receiveCountPerSec() const {return packets_in_sec;} - const ullong * receiveCountPerSec_ptr() const {return &packets_in_sec;} - ullong sendCountPerSec() const {return packets_out_sec;} - const ullong * sendCountPerSec_ptr() const {return &packets_out_sec;} - ullong receiveBytesPerSec() const {return bytes_in_sec;} - const ullong * receiveBytesPerSec_ptr() const {return &bytes_in_sec;} - ullong sendBytesPerSec() const {return bytes_out_sec;} - const ullong * sendBytesPerSec_ptr() const {return &bytes_out_sec;} - ullong receiveCount() const {return receive_count;} - const ullong * receiveCount_ptr() const {return &receive_count;} - ullong wrongCount() const {return wrong_count;} - const ullong * wrongCount_ptr() const {return &wrong_count;} - ullong sendCount() const {return send_count;} - const ullong * sendCount_ptr() const {return &send_count;} - ullong missedCount() const {return missed_count;} - const ullong * missedCount_ptr() const {return &missed_count;} - PIProtocol::Quality quality() const {return net_diag;} // receive quality - const int * quality_ptr() const {return (int * )&net_diag;} // receive quality pointer - PIString receiverDeviceName() const {return devReceiverName;} - PIString senderDeviceName() const {return devSenderName;} - PIString receiverDeviceState() const {return devReceiverState;} - const PIString * receiverDeviceState_ptr() const {return &devReceiverState;} - PIString senderDeviceState() const {return devSenderState;} - const PIString * senderDeviceState_ptr() const {return &devSenderState;} - PIString receiveSpeed() const {return speedIn;} - const PIString * receiveSpeed_ptr() const {return &speedIn;} - PIString sendSpeed() const {return speedOut;} - const PIString * sendSpeed_ptr() const {return &speedOut;} - - void * receiveData() {return dataPtr;} - void * sendData() {return sendDataPtr;} - - PIPacketExtractor * packetExtractor() {return packet_ext;} -// PIByteArray lastHeader() {return packet_ext->lastHeader();} - - EVENT0(receiverStarted) - EVENT0(receiverStopped) - EVENT0(senderStarted) - EVENT0(senderStopped) - EVENT1(received, bool, validate_is_ok) - EVENT2(qualityChanged, PIProtocol::Quality, new_quality, PIProtocol::Quality, old_quality) - -protected: - virtual bool receive(uchar * data, int size) {if (dataPtr != 0) memcpy(dataPtr, data, size); return true;} // executed when raw data received, break if 'false' return - virtual bool validate() {return true;} // function for validate algorithm and save data from dataPtr to external struct - virtual bool headerValidate(uchar * src, uchar * rec, int size) {for (int i = 0; i < size; ++i) if (src[i] != rec[i]) return false; return true;} // function for validate header (COM-port and headerSize > 0) - virtual uint checksum_i(void * data, int size) { // function for checksum (uint) - uint c = 0; - for (int i = 0; i < size; ++i) - c += ((uchar*)data)[i]; - return ~(c + 1); - } - virtual uchar checksum_c(void * data, int size) { // function for checksum (uchar) - uchar c = 0; - for (int i = 0; i < size; ++i) - c += ((uchar*)data)[i]; - return ~(c + 1); - } - virtual bool aboutSend() {return true;} // executed before send data, if return 'false' then data is not sending - - void init(); - void init_sender(PIConfig::Entry & b, PIConfig::Entry & sb, const PIString & config); - void init_receiver(PIConfig::Entry & b, PIConfig::Entry & rb, const PIString & config); - void check_state(); - void calc_freq(); - void calc_diag(); - - PISerial * ser; - PIEthernet * eth; - uint dataSize, headerSize, sendDataSize; - uchar * dataPtr, * headerPtr, * sendDataPtr; - -private: - static void sendEvent(void * e, int) {((PIProtocol * )e)->send();} - static bool receiveEvent(void * t, uchar * data, int size); - static bool headerValidateEvent(void * t, uchar * src, uchar * rec, int size) {return ((PIProtocol * )t)->headerValidate(src, rec, size);} - static void diagEvent(void * t, int); - static void secEvent(void * t, int); - - void setMultiProtocolOwner(PIMultiProtocolBase * mp) {mp_owner = mp;} - PIMultiProtocolBase * multiProtocolOwner() const {return mp_owner;} - void changeDisconnectTimeout(); - - ReceiveFunc ret_func; - PIPacketExtractor * packet_ext; - PITimer * diagTimer, * sendTimer, * secTimer; - PITimeMeasurer diag_tm; - PIMultiProtocolBase * mp_owner; - PIProtocol::Type type_send, type_rec; - PIProtocol::Quality net_diag; - PIDeque last_freq; - PIDeque last_packets; - PIString protName, devReceiverName, devReceiverState, devSenderName, devSenderState, speedIn, speedOut; - bool work, new_mp_prot; - float exp_freq, send_freq, ifreq, immediate_freq, integral_freq, timeout_; - int packets[2], pckt_cnt, pckt_cnt_max; - char cur_pckt; - ullong wrong_count, receive_count, send_count, missed_count, packets_in_sec, packets_out_sec, bytes_in_sec, bytes_out_sec; - -}; - -#endif // PIPROTOCOL_H diff --git a/qad/libs/CMakeLists.txt b/libs/CMakeLists.txt similarity index 100% rename from qad/libs/CMakeLists.txt rename to libs/CMakeLists.txt diff --git a/qad/libs/application/CMakeLists.txt b/libs/application/CMakeLists.txt similarity index 100% rename from qad/libs/application/CMakeLists.txt rename to libs/application/CMakeLists.txt diff --git a/qad/libs/application/aboutwindow.cpp b/libs/application/aboutwindow.cpp similarity index 100% rename from qad/libs/application/aboutwindow.cpp rename to libs/application/aboutwindow.cpp diff --git a/qad/libs/application/aboutwindow.h b/libs/application/aboutwindow.h similarity index 100% rename from qad/libs/application/aboutwindow.h rename to libs/application/aboutwindow.h diff --git a/qad/libs/application/aboutwindow.ui b/libs/application/aboutwindow.ui similarity index 100% rename from qad/libs/application/aboutwindow.ui rename to libs/application/aboutwindow.ui diff --git a/qad/libs/application/edockwidget.cpp b/libs/application/edockwidget.cpp similarity index 100% rename from qad/libs/application/edockwidget.cpp rename to libs/application/edockwidget.cpp diff --git a/qad/libs/application/edockwidget.h b/libs/application/edockwidget.h similarity index 100% rename from qad/libs/application/edockwidget.h rename to libs/application/edockwidget.h diff --git a/qad/libs/application/emainwindow.cpp b/libs/application/emainwindow.cpp similarity index 100% rename from qad/libs/application/emainwindow.cpp rename to libs/application/emainwindow.cpp diff --git a/qad/libs/application/emainwindow.h b/libs/application/emainwindow.h similarity index 100% rename from qad/libs/application/emainwindow.h rename to libs/application/emainwindow.h diff --git a/qad/libs/application/etabwidget.cpp b/libs/application/etabwidget.cpp similarity index 100% rename from qad/libs/application/etabwidget.cpp rename to libs/application/etabwidget.cpp diff --git a/qad/libs/application/etabwidget.h b/libs/application/etabwidget.h similarity index 100% rename from qad/libs/application/etabwidget.h rename to libs/application/etabwidget.h diff --git a/qad/libs/application/historyview.cpp b/libs/application/historyview.cpp similarity index 100% rename from qad/libs/application/historyview.cpp rename to libs/application/historyview.cpp diff --git a/qad/libs/application/historyview.h b/libs/application/historyview.h similarity index 100% rename from qad/libs/application/historyview.h rename to libs/application/historyview.h diff --git a/qad/libs/application/lang/qad_application_en.ts b/libs/application/lang/qad_application_en.ts similarity index 100% rename from qad/libs/application/lang/qad_application_en.ts rename to libs/application/lang/qad_application_en.ts diff --git a/qad/libs/application/lang/qad_application_ru.ts b/libs/application/lang/qad_application_ru.ts similarity index 100% rename from qad/libs/application/lang/qad_application_ru.ts rename to libs/application/lang/qad_application_ru.ts diff --git a/qad/libs/application/lang/update.bat b/libs/application/lang/update.bat similarity index 100% rename from qad/libs/application/lang/update.bat rename to libs/application/lang/update.bat diff --git a/qad/libs/application/logview.cpp b/libs/application/logview.cpp similarity index 100% rename from qad/libs/application/logview.cpp rename to libs/application/logview.cpp diff --git a/qad/libs/application/logview.h b/libs/application/logview.h similarity index 100% rename from qad/libs/application/logview.h rename to libs/application/logview.h diff --git a/qad/libs/application/logview.ui b/libs/application/logview.ui similarity index 100% rename from qad/libs/application/logview.ui rename to libs/application/logview.ui diff --git a/qad/libs/application/plugin/CMakeLists.txt b/libs/application/plugin/CMakeLists.txt similarity index 100% rename from qad/libs/application/plugin/CMakeLists.txt rename to libs/application/plugin/CMakeLists.txt diff --git a/qad/libs/application/plugin/edockwidgetplugin.cpp b/libs/application/plugin/edockwidgetplugin.cpp similarity index 100% rename from qad/libs/application/plugin/edockwidgetplugin.cpp rename to libs/application/plugin/edockwidgetplugin.cpp diff --git a/qad/libs/application/plugin/edockwidgetplugin.h b/libs/application/plugin/edockwidgetplugin.h similarity index 100% rename from qad/libs/application/plugin/edockwidgetplugin.h rename to libs/application/plugin/edockwidgetplugin.h diff --git a/qad/libs/application/plugin/emainwindowplugin.cpp b/libs/application/plugin/emainwindowplugin.cpp similarity index 100% rename from qad/libs/application/plugin/emainwindowplugin.cpp rename to libs/application/plugin/emainwindowplugin.cpp diff --git a/qad/libs/application/plugin/emainwindowplugin.h b/libs/application/plugin/emainwindowplugin.h similarity index 100% rename from qad/libs/application/plugin/emainwindowplugin.h rename to libs/application/plugin/emainwindowplugin.h diff --git a/qad/libs/application/plugin/historyviewplugin.cpp b/libs/application/plugin/historyviewplugin.cpp similarity index 100% rename from qad/libs/application/plugin/historyviewplugin.cpp rename to libs/application/plugin/historyviewplugin.cpp diff --git a/qad/libs/application/plugin/historyviewplugin.h b/libs/application/plugin/historyviewplugin.h similarity index 100% rename from qad/libs/application/plugin/historyviewplugin.h rename to libs/application/plugin/historyviewplugin.h diff --git a/qad/libs/application/plugin/logviewplugin.cpp b/libs/application/plugin/logviewplugin.cpp similarity index 100% rename from qad/libs/application/plugin/logviewplugin.cpp rename to libs/application/plugin/logviewplugin.cpp diff --git a/qad/libs/application/plugin/logviewplugin.h b/libs/application/plugin/logviewplugin.h similarity index 100% rename from qad/libs/application/plugin/logviewplugin.h rename to libs/application/plugin/logviewplugin.h diff --git a/qad/libs/application/plugin/qad_application.cpp b/libs/application/plugin/qad_application.cpp similarity index 100% rename from qad/libs/application/plugin/qad_application.cpp rename to libs/application/plugin/qad_application.cpp diff --git a/qad/libs/application/plugin/qad_application.h b/libs/application/plugin/qad_application.h similarity index 100% rename from qad/libs/application/plugin/qad_application.h rename to libs/application/plugin/qad_application.h diff --git a/qad/libs/application/qad_application.qrc b/libs/application/qad_application.qrc similarity index 100% rename from qad/libs/application/qad_application.qrc rename to libs/application/qad_application.qrc diff --git a/qad/libs/application/qsingleapplication.cpp b/libs/application/qsingleapplication.cpp similarity index 100% rename from qad/libs/application/qsingleapplication.cpp rename to libs/application/qsingleapplication.cpp diff --git a/qad/libs/application/qsingleapplication.h b/libs/application/qsingleapplication.h similarity index 100% rename from qad/libs/application/qsingleapplication.h rename to libs/application/qsingleapplication.h diff --git a/qad/libs/application/ribbon.cpp b/libs/application/ribbon.cpp similarity index 100% rename from qad/libs/application/ribbon.cpp rename to libs/application/ribbon.cpp diff --git a/qad/libs/application/ribbon.h b/libs/application/ribbon.h similarity index 100% rename from qad/libs/application/ribbon.h rename to libs/application/ribbon.h diff --git a/qad/libs/blockview/CMakeLists.txt b/libs/blockview/CMakeLists.txt similarity index 100% rename from qad/libs/blockview/CMakeLists.txt rename to libs/blockview/CMakeLists.txt diff --git a/qad/libs/blockview/alignedtextitem.cpp b/libs/blockview/alignedtextitem.cpp similarity index 100% rename from qad/libs/blockview/alignedtextitem.cpp rename to libs/blockview/alignedtextitem.cpp diff --git a/qad/libs/blockview/alignedtextitem.h b/libs/blockview/alignedtextitem.h similarity index 100% rename from qad/libs/blockview/alignedtextitem.h rename to libs/blockview/alignedtextitem.h diff --git a/qad/libs/blockview/blockbase.cpp b/libs/blockview/blockbase.cpp similarity index 100% rename from qad/libs/blockview/blockbase.cpp rename to libs/blockview/blockbase.cpp diff --git a/qad/libs/blockview/blockbase.h b/libs/blockview/blockbase.h similarity index 100% rename from qad/libs/blockview/blockbase.h rename to libs/blockview/blockbase.h diff --git a/qad/libs/blockview/blockbusitem.cpp b/libs/blockview/blockbusitem.cpp similarity index 100% rename from qad/libs/blockview/blockbusitem.cpp rename to libs/blockview/blockbusitem.cpp diff --git a/qad/libs/blockview/blockbusitem.h b/libs/blockview/blockbusitem.h similarity index 100% rename from qad/libs/blockview/blockbusitem.h rename to libs/blockview/blockbusitem.h diff --git a/qad/libs/blockview/blockeditor.cpp b/libs/blockview/blockeditor.cpp similarity index 100% rename from qad/libs/blockview/blockeditor.cpp rename to libs/blockview/blockeditor.cpp diff --git a/qad/libs/blockview/blockeditor.h b/libs/blockview/blockeditor.h similarity index 100% rename from qad/libs/blockview/blockeditor.h rename to libs/blockview/blockeditor.h diff --git a/qad/libs/blockview/blockeditor.ui b/libs/blockview/blockeditor.ui similarity index 100% rename from qad/libs/blockview/blockeditor.ui rename to libs/blockview/blockeditor.ui diff --git a/qad/libs/blockview/blockitem.cpp b/libs/blockview/blockitem.cpp similarity index 100% rename from qad/libs/blockview/blockitem.cpp rename to libs/blockview/blockitem.cpp diff --git a/qad/libs/blockview/blockitem.h b/libs/blockview/blockitem.h similarity index 100% rename from qad/libs/blockview/blockitem.h rename to libs/blockview/blockitem.h diff --git a/qad/libs/blockview/blockitempin.cpp b/libs/blockview/blockitempin.cpp similarity index 100% rename from qad/libs/blockview/blockitempin.cpp rename to libs/blockview/blockitempin.cpp diff --git a/qad/libs/blockview/blockitempin.h b/libs/blockview/blockitempin.h similarity index 100% rename from qad/libs/blockview/blockitempin.h rename to libs/blockview/blockitempin.h diff --git a/qad/libs/blockview/blockview.cpp b/libs/blockview/blockview.cpp similarity index 100% rename from qad/libs/blockview/blockview.cpp rename to libs/blockview/blockview.cpp diff --git a/qad/libs/blockview/blockview.h b/libs/blockview/blockview.h similarity index 100% rename from qad/libs/blockview/blockview.h rename to libs/blockview/blockview.h diff --git a/qad/libs/blockview/blockviewwavetrace.cpp b/libs/blockview/blockviewwavetrace.cpp similarity index 100% rename from qad/libs/blockview/blockviewwavetrace.cpp rename to libs/blockview/blockviewwavetrace.cpp diff --git a/qad/libs/blockview/blockviewwavetrace.h b/libs/blockview/blockviewwavetrace.h similarity index 100% rename from qad/libs/blockview/blockviewwavetrace.h rename to libs/blockview/blockviewwavetrace.h diff --git a/qad/libs/blockview/drawtools.cpp b/libs/blockview/drawtools.cpp similarity index 100% rename from qad/libs/blockview/drawtools.cpp rename to libs/blockview/drawtools.cpp diff --git a/qad/libs/blockview/drawtools.h b/libs/blockview/drawtools.h similarity index 100% rename from qad/libs/blockview/drawtools.h rename to libs/blockview/drawtools.h diff --git a/qad/libs/blockview/drawtools.ui b/libs/blockview/drawtools.ui similarity index 100% rename from qad/libs/blockview/drawtools.ui rename to libs/blockview/drawtools.ui diff --git a/qad/libs/blockview/lang/qad_blockview_en.ts b/libs/blockview/lang/qad_blockview_en.ts similarity index 100% rename from qad/libs/blockview/lang/qad_blockview_en.ts rename to libs/blockview/lang/qad_blockview_en.ts diff --git a/qad/libs/blockview/lang/qad_blockview_ru.ts b/libs/blockview/lang/qad_blockview_ru.ts similarity index 100% rename from qad/libs/blockview/lang/qad_blockview_ru.ts rename to libs/blockview/lang/qad_blockview_ru.ts diff --git a/qad/libs/blockview/lang/update.bat b/libs/blockview/lang/update.bat similarity index 100% rename from qad/libs/blockview/lang/update.bat rename to libs/blockview/lang/update.bat diff --git a/qad/libs/blockview/plugin/CMakeLists.txt b/libs/blockview/plugin/CMakeLists.txt similarity index 100% rename from qad/libs/blockview/plugin/CMakeLists.txt rename to libs/blockview/plugin/CMakeLists.txt diff --git a/qad/libs/blockview/plugin/blockviewplugin.cpp b/libs/blockview/plugin/blockviewplugin.cpp similarity index 100% rename from qad/libs/blockview/plugin/blockviewplugin.cpp rename to libs/blockview/plugin/blockviewplugin.cpp diff --git a/qad/libs/blockview/plugin/blockviewplugin.h b/libs/blockview/plugin/blockviewplugin.h similarity index 100% rename from qad/libs/blockview/plugin/blockviewplugin.h rename to libs/blockview/plugin/blockviewplugin.h diff --git a/qad/libs/blockview/plugin/qad_blockview.cpp b/libs/blockview/plugin/qad_blockview.cpp similarity index 100% rename from qad/libs/blockview/plugin/qad_blockview.cpp rename to libs/blockview/plugin/qad_blockview.cpp diff --git a/qad/libs/blockview/plugin/qad_blockview.h b/libs/blockview/plugin/qad_blockview.h similarity index 100% rename from qad/libs/blockview/plugin/qad_blockview.h rename to libs/blockview/plugin/qad_blockview.h diff --git a/qad/libs/blockview/qad_blockview.qrc b/libs/blockview/qad_blockview.qrc similarity index 100% rename from qad/libs/blockview/qad_blockview.qrc rename to libs/blockview/qad_blockview.qrc diff --git a/qad/libs/doc/CMakeLists.txt b/libs/doc/CMakeLists.txt similarity index 100% rename from qad/libs/doc/CMakeLists.txt rename to libs/doc/CMakeLists.txt diff --git a/qad/libs/doc/markdown.cpp b/libs/doc/markdown.cpp similarity index 100% rename from qad/libs/doc/markdown.cpp rename to libs/doc/markdown.cpp diff --git a/qad/libs/doc/markdown.h b/libs/doc/markdown.h similarity index 100% rename from qad/libs/doc/markdown.h rename to libs/doc/markdown.h diff --git a/qad/libs/graphic/CMakeLists.txt b/libs/graphic/CMakeLists.txt similarity index 100% rename from qad/libs/graphic/CMakeLists.txt rename to libs/graphic/CMakeLists.txt diff --git a/qad/libs/graphic/graphic.cpp b/libs/graphic/graphic.cpp similarity index 100% rename from qad/libs/graphic/graphic.cpp rename to libs/graphic/graphic.cpp diff --git a/qad/libs/graphic/graphic.h b/libs/graphic/graphic.h similarity index 100% rename from qad/libs/graphic/graphic.h rename to libs/graphic/graphic.h diff --git a/qad/libs/graphic/graphic.ui b/libs/graphic/graphic.ui similarity index 100% rename from qad/libs/graphic/graphic.ui rename to libs/graphic/graphic.ui diff --git a/qad/libs/graphic/graphic_conf.cpp b/libs/graphic/graphic_conf.cpp similarity index 100% rename from qad/libs/graphic/graphic_conf.cpp rename to libs/graphic/graphic_conf.cpp diff --git a/qad/libs/graphic/graphic_conf.h b/libs/graphic/graphic_conf.h similarity index 100% rename from qad/libs/graphic/graphic_conf.h rename to libs/graphic/graphic_conf.h diff --git a/qad/libs/graphic/graphic_conf.ui b/libs/graphic/graphic_conf.ui similarity index 100% rename from qad/libs/graphic/graphic_conf.ui rename to libs/graphic/graphic_conf.ui diff --git a/qad/libs/graphic/lang/qad_graphic_en.ts b/libs/graphic/lang/qad_graphic_en.ts similarity index 100% rename from qad/libs/graphic/lang/qad_graphic_en.ts rename to libs/graphic/lang/qad_graphic_en.ts diff --git a/qad/libs/graphic/lang/qad_graphic_ru.ts b/libs/graphic/lang/qad_graphic_ru.ts similarity index 100% rename from qad/libs/graphic/lang/qad_graphic_ru.ts rename to libs/graphic/lang/qad_graphic_ru.ts diff --git a/qad/libs/graphic/lang/update.bat b/libs/graphic/lang/update.bat similarity index 100% rename from qad/libs/graphic/lang/update.bat rename to libs/graphic/lang/update.bat diff --git a/qad/libs/graphic/plugin/CMakeLists.txt b/libs/graphic/plugin/CMakeLists.txt similarity index 100% rename from qad/libs/graphic/plugin/CMakeLists.txt rename to libs/graphic/plugin/CMakeLists.txt diff --git a/qad/libs/graphic/plugin/graphicplugin.cpp b/libs/graphic/plugin/graphicplugin.cpp similarity index 100% rename from qad/libs/graphic/plugin/graphicplugin.cpp rename to libs/graphic/plugin/graphicplugin.cpp diff --git a/qad/libs/graphic/plugin/graphicplugin.h b/libs/graphic/plugin/graphicplugin.h similarity index 100% rename from qad/libs/graphic/plugin/graphicplugin.h rename to libs/graphic/plugin/graphicplugin.h diff --git a/qad/libs/graphic/plugin/qad_graphic.cpp b/libs/graphic/plugin/qad_graphic.cpp similarity index 100% rename from qad/libs/graphic/plugin/qad_graphic.cpp rename to libs/graphic/plugin/qad_graphic.cpp diff --git a/qad/libs/graphic/plugin/qad_graphic.h b/libs/graphic/plugin/qad_graphic.h similarity index 100% rename from qad/libs/graphic/plugin/qad_graphic.h rename to libs/graphic/plugin/qad_graphic.h diff --git a/qad/libs/graphic/qad_graphic.qrc b/libs/graphic/qad_graphic.qrc similarity index 100% rename from qad/libs/graphic/qad_graphic.qrc rename to libs/graphic/qad_graphic.qrc diff --git a/qad/libs/graphic/uglwidget.h b/libs/graphic/uglwidget.h similarity index 100% rename from qad/libs/graphic/uglwidget.h rename to libs/graphic/uglwidget.h diff --git a/qad/libs/graphic/uwidget.h b/libs/graphic/uwidget.h similarity index 100% rename from qad/libs/graphic/uwidget.h rename to libs/graphic/uwidget.h diff --git a/piqt/libs/core/CMakeLists.txt b/libs/piqt/CMakeLists.txt similarity index 100% rename from piqt/libs/core/CMakeLists.txt rename to libs/piqt/CMakeLists.txt diff --git a/piqt/libs/core/piqt.cpp b/libs/piqt/piqt.cpp similarity index 100% rename from piqt/libs/core/piqt.cpp rename to libs/piqt/piqt.cpp diff --git a/piqt/libs/core/piqt.h b/libs/piqt/piqt.h similarity index 100% rename from piqt/libs/core/piqt.h rename to libs/piqt/piqt.h diff --git a/piqt/libs/core/qpiconnection.cpp b/libs/piqt/qpiconnection.cpp similarity index 100% rename from piqt/libs/core/qpiconnection.cpp rename to libs/piqt/qpiconnection.cpp diff --git a/piqt/libs/core/qpiconnection.h b/libs/piqt/qpiconnection.h similarity index 100% rename from piqt/libs/core/qpiconnection.h rename to libs/piqt/qpiconnection.h diff --git a/piqt/libs/widgets/CMakeLists.txt b/libs/piqt_widgets/CMakeLists.txt similarity index 100% rename from piqt/libs/widgets/CMakeLists.txt rename to libs/piqt_widgets/CMakeLists.txt diff --git a/piqt/libs/widgets/piqt_connection_edit.cpp b/libs/piqt_widgets/piqt_connection_edit.cpp similarity index 100% rename from piqt/libs/widgets/piqt_connection_edit.cpp rename to libs/piqt_widgets/piqt_connection_edit.cpp diff --git a/piqt/libs/widgets/piqt_connection_edit.h b/libs/piqt_widgets/piqt_connection_edit.h similarity index 100% rename from piqt/libs/widgets/piqt_connection_edit.h rename to libs/piqt_widgets/piqt_connection_edit.h diff --git a/piqt/libs/widgets/piqt_connection_edit.ui b/libs/piqt_widgets/piqt_connection_edit.ui similarity index 100% rename from piqt/libs/widgets/piqt_connection_edit.ui rename to libs/piqt_widgets/piqt_connection_edit.ui diff --git a/piqt/libs/widgets/piqt_connection_view.cpp b/libs/piqt_widgets/piqt_connection_view.cpp similarity index 100% rename from piqt/libs/widgets/piqt_connection_view.cpp rename to libs/piqt_widgets/piqt_connection_view.cpp diff --git a/piqt/libs/widgets/piqt_connection_view.h b/libs/piqt_widgets/piqt_connection_view.h similarity index 100% rename from piqt/libs/widgets/piqt_connection_view.h rename to libs/piqt_widgets/piqt_connection_view.h diff --git a/piqt/libs/widgets/piqt_highlighter.cpp b/libs/piqt_widgets/piqt_highlighter.cpp similarity index 100% rename from piqt/libs/widgets/piqt_highlighter.cpp rename to libs/piqt_widgets/piqt_highlighter.cpp diff --git a/piqt/libs/widgets/piqt_highlighter.h b/libs/piqt_widgets/piqt_highlighter.h similarity index 100% rename from piqt/libs/widgets/piqt_highlighter.h rename to libs/piqt_widgets/piqt_highlighter.h diff --git a/piqt/libs/widgets/piqt_iodevice_edit.cpp b/libs/piqt_widgets/piqt_iodevice_edit.cpp similarity index 100% rename from piqt/libs/widgets/piqt_iodevice_edit.cpp rename to libs/piqt_widgets/piqt_iodevice_edit.cpp diff --git a/piqt/libs/widgets/piqt_iodevice_edit.h b/libs/piqt_widgets/piqt_iodevice_edit.h similarity index 100% rename from piqt/libs/widgets/piqt_iodevice_edit.h rename to libs/piqt_widgets/piqt_iodevice_edit.h diff --git a/piqt/libs/widgets/piqt_iodevice_edit_dialog.cpp b/libs/piqt_widgets/piqt_iodevice_edit_dialog.cpp similarity index 100% rename from piqt/libs/widgets/piqt_iodevice_edit_dialog.cpp rename to libs/piqt_widgets/piqt_iodevice_edit_dialog.cpp diff --git a/piqt/libs/widgets/piqt_iodevice_edit_dialog.h b/libs/piqt_widgets/piqt_iodevice_edit_dialog.h similarity index 100% rename from piqt/libs/widgets/piqt_iodevice_edit_dialog.h rename to libs/piqt_widgets/piqt_iodevice_edit_dialog.h diff --git a/piqt/libs/widgets/piqt_iodevice_edit_dialog.ui b/libs/piqt_widgets/piqt_iodevice_edit_dialog.ui similarity index 100% rename from piqt/libs/widgets/piqt_iodevice_edit_dialog.ui rename to libs/piqt_widgets/piqt_iodevice_edit_dialog.ui diff --git a/piqt/libs/qcd/CMakeLists.txt b/libs/qcd/CMakeLists.txt similarity index 100% rename from piqt/libs/qcd/CMakeLists.txt rename to libs/qcd/CMakeLists.txt diff --git a/piqt/libs/qcd/qcd_core.cpp b/libs/qcd/qcd_core.cpp similarity index 100% rename from piqt/libs/qcd/qcd_core.cpp rename to libs/qcd/qcd_core.cpp diff --git a/piqt/libs/qcd/qcd_core.h b/libs/qcd/qcd_core.h similarity index 100% rename from piqt/libs/qcd/qcd_core.h rename to libs/qcd/qcd_core.h diff --git a/piqt/libs/qcd/qcd_graphic.cpp b/libs/qcd/qcd_graphic.cpp similarity index 100% rename from piqt/libs/qcd/qcd_graphic.cpp rename to libs/qcd/qcd_graphic.cpp diff --git a/piqt/libs/qcd/qcd_graphic.h b/libs/qcd/qcd_graphic.h similarity index 100% rename from piqt/libs/qcd/qcd_graphic.h rename to libs/qcd/qcd_graphic.h diff --git a/piqt/libs/qcd/qcd_graphic.ui b/libs/qcd/qcd_graphic.ui similarity index 100% rename from piqt/libs/qcd/qcd_graphic.ui rename to libs/qcd/qcd_graphic.ui diff --git a/piqt/libs/qcd/qcd_modedialog.cpp b/libs/qcd/qcd_modedialog.cpp similarity index 100% rename from piqt/libs/qcd/qcd_modedialog.cpp rename to libs/qcd/qcd_modedialog.cpp diff --git a/piqt/libs/qcd/qcd_modedialog.h b/libs/qcd/qcd_modedialog.h similarity index 100% rename from piqt/libs/qcd/qcd_modedialog.h rename to libs/qcd/qcd_modedialog.h diff --git a/piqt/libs/qcd/qcd_modedialog.ui b/libs/qcd/qcd_modedialog.ui similarity index 100% rename from piqt/libs/qcd/qcd_modedialog.ui rename to libs/qcd/qcd_modedialog.ui diff --git a/piqt/libs/qcd/qcd_model.cpp b/libs/qcd/qcd_model.cpp similarity index 100% rename from piqt/libs/qcd/qcd_model.cpp rename to libs/qcd/qcd_model.cpp diff --git a/piqt/libs/qcd/qcd_model.h b/libs/qcd/qcd_model.h similarity index 100% rename from piqt/libs/qcd/qcd_model.h rename to libs/qcd/qcd_model.h diff --git a/piqt/libs/qcd/qcd_view.cpp b/libs/qcd/qcd_view.cpp similarity index 100% rename from piqt/libs/qcd/qcd_view.cpp rename to libs/qcd/qcd_view.cpp diff --git a/piqt/libs/qcd/qcd_view.h b/libs/qcd/qcd_view.h similarity index 100% rename from piqt/libs/qcd/qcd_view.h rename to libs/qcd/qcd_view.h diff --git a/qglview/CMakeLists.txt b/libs/qglview/CMakeLists.txt similarity index 97% rename from qglview/CMakeLists.txt rename to libs/qglview/CMakeLists.txt index 018fbe7..b6fcdf8 100644 --- a/qglview/CMakeLists.txt +++ b/libs/qglview/CMakeLists.txt @@ -1,8 +1,8 @@ -find_package(OpenGL REQUIRED) -_qt_project(qglview FALSE "QAD" "Gui;OpenGL;Xml" "qad_widgets;qad_utils;${OPENGL_LIBRARIES}") -_qt_install(qglview FALSE "qad" "out_HDR" "out_QM") - -qt_sources(test_SRC DIR "qglview_test") -qt_wrap(${test_SRC} CPPS test_CPP) -qt_add_executable(qglview_test test_CPP) -qt_target_link_libraries(qglview_test qglview) +find_package(OpenGL REQUIRED) +_qt_project(qglview FALSE "QAD" "Gui;OpenGL;Xml" "qad_widgets;qad_utils;${OPENGL_LIBRARIES}") +_qt_install(qglview FALSE "qad" "out_HDR" "out_QM") + +qt_sources(test_SRC DIR "qglview_test") +qt_wrap(${test_SRC} CPPS test_CPP) +qt_add_executable(qglview_test test_CPP) +qt_target_link_libraries(qglview_test qglview) diff --git a/cd_utils/LICENSE.txt b/libs/qglview/LICENSE.txt similarity index 100% rename from cd_utils/LICENSE.txt rename to libs/qglview/LICENSE.txt diff --git a/qglview/glcamera.cpp b/libs/qglview/glcamera.cpp similarity index 100% rename from qglview/glcamera.cpp rename to libs/qglview/glcamera.cpp diff --git a/qglview/glcamera.h b/libs/qglview/glcamera.h similarity index 100% rename from qglview/glcamera.h rename to libs/qglview/glcamera.h diff --git a/qglview/glframebuffer.cpp b/libs/qglview/glframebuffer.cpp similarity index 100% rename from qglview/glframebuffer.cpp rename to libs/qglview/glframebuffer.cpp diff --git a/qglview/glframebuffer.h b/libs/qglview/glframebuffer.h similarity index 100% rename from qglview/glframebuffer.h rename to libs/qglview/glframebuffer.h diff --git a/qglview/glmaterial.cpp b/libs/qglview/glmaterial.cpp similarity index 100% rename from qglview/glmaterial.cpp rename to libs/qglview/glmaterial.cpp diff --git a/qglview/glmaterial.h b/libs/qglview/glmaterial.h similarity index 100% rename from qglview/glmaterial.h rename to libs/qglview/glmaterial.h diff --git a/qglview/globject.cpp b/libs/qglview/globject.cpp similarity index 100% rename from qglview/globject.cpp rename to libs/qglview/globject.cpp diff --git a/qglview/globject.h b/libs/qglview/globject.h similarity index 100% rename from qglview/globject.h rename to libs/qglview/globject.h diff --git a/qglview/globject_editor.cpp b/libs/qglview/globject_editor.cpp similarity index 100% rename from qglview/globject_editor.cpp rename to libs/qglview/globject_editor.cpp diff --git a/qglview/globject_editor.h b/libs/qglview/globject_editor.h similarity index 100% rename from qglview/globject_editor.h rename to libs/qglview/globject_editor.h diff --git a/qglview/globject_editor.ui b/libs/qglview/globject_editor.ui similarity index 100% rename from qglview/globject_editor.ui rename to libs/qglview/globject_editor.ui diff --git a/qglview/glparticles_system.cpp b/libs/qglview/glparticles_system.cpp similarity index 100% rename from qglview/glparticles_system.cpp rename to libs/qglview/glparticles_system.cpp diff --git a/qglview/glparticles_system.h b/libs/qglview/glparticles_system.h similarity index 100% rename from qglview/glparticles_system.h rename to libs/qglview/glparticles_system.h diff --git a/qglview/glprimitives.cpp b/libs/qglview/glprimitives.cpp similarity index 100% rename from qglview/glprimitives.cpp rename to libs/qglview/glprimitives.cpp diff --git a/qglview/glprimitives.h b/libs/qglview/glprimitives.h similarity index 100% rename from qglview/glprimitives.h rename to libs/qglview/glprimitives.h diff --git a/qglview/glrendererbase.cpp b/libs/qglview/glrendererbase.cpp similarity index 100% rename from qglview/glrendererbase.cpp rename to libs/qglview/glrendererbase.cpp diff --git a/qglview/glrendererbase.h b/libs/qglview/glrendererbase.h similarity index 100% rename from qglview/glrendererbase.h rename to libs/qglview/glrendererbase.h diff --git a/qglview/glshaders.cpp b/libs/qglview/glshaders.cpp similarity index 100% rename from qglview/glshaders.cpp rename to libs/qglview/glshaders.cpp diff --git a/qglview/glshaders.h b/libs/qglview/glshaders.h similarity index 100% rename from qglview/glshaders.h rename to libs/qglview/glshaders.h diff --git a/qglview/gltexture_manager.cpp b/libs/qglview/gltexture_manager.cpp similarity index 100% rename from qglview/gltexture_manager.cpp rename to libs/qglview/gltexture_manager.cpp diff --git a/qglview/gltexture_manager.h b/libs/qglview/gltexture_manager.h similarity index 100% rename from qglview/gltexture_manager.h rename to libs/qglview/gltexture_manager.h diff --git a/qglview/gltypes.cpp b/libs/qglview/gltypes.cpp similarity index 100% rename from qglview/gltypes.cpp rename to libs/qglview/gltypes.cpp diff --git a/qglview/gltypes.h b/libs/qglview/gltypes.h similarity index 100% rename from qglview/gltypes.h rename to libs/qglview/gltypes.h diff --git a/qglview/glvbo.cpp b/libs/qglview/glvbo.cpp similarity index 100% rename from qglview/glvbo.cpp rename to libs/qglview/glvbo.cpp diff --git a/qglview/glvbo.h b/libs/qglview/glvbo.h similarity index 100% rename from qglview/glvbo.h rename to libs/qglview/glvbo.h diff --git a/qglview/glwidget.cpp b/libs/qglview/glwidget.cpp similarity index 94% rename from qglview/glwidget.cpp rename to libs/qglview/glwidget.cpp index c6d75f8..22c905a 100644 --- a/qglview/glwidget.cpp +++ b/libs/qglview/glwidget.cpp @@ -1,236 +1,236 @@ -#include "glwidget.h" -#include "renderer_simple.h" -#include "renderer_deferred_shading.h" -#include - - -GLWidget::GLWidget(QWidget *parent) : QWidget(parent) { - view_ = new QGLView(); - view_->setFlags(windowFlags() | Qt::FramelessWindowHint); - container = QWidget::createWindowContainer(view_, this); - lay = new QVBoxLayout(this); - lay->addWidget(container); - lay->setContentsMargins(0, 0, 0, 0); - lay->setSpacing(0); - setMouseTracking(true); - setWindowIcon(QIcon("://icons/qglview.png")); - connect(view_, &QGLView::doubleClick, this, &GLWidget::viewDoubleClicked); -} - - -QColor GLWidget::backColor() const { - return view_->backColor(); -} - - -qreal GLWidget::lineWidth() const { - return view_->lineWidth(); -} - - -qreal GLWidget::FOV() const { - return view_->FOV(); -} - - -qreal GLWidget::depthStart() const { - return view_->depthStart(); -} - - -qreal GLWidget::depthEnd() const { - return view_->depthEnd(); -} - - -QColor GLWidget::ambientColor() const { - return view_->ambientColor(); -} - - -bool GLWidget::isLightEnabled() const { - return view_->isLightEnabled(); -} - - -bool GLWidget::isGrabMouseEnabled() const { - return view_->isGrabMouseEnabled(); -} - - -bool GLWidget::isMouseRotateEnabled() const { - return view_->isMouseRotateEnabled(); -} - - -bool GLWidget::isMouseSelectionEnabled() const { - return view_->isMouseSelectionEnabled(); -} - - -bool GLWidget::isCameraOrbit() const -{ - return view_->isCameraOrbit(); -} - - -bool GLWidget::isHoverHaloEnabled() const { - return view_->isHoverHaloEnabled(); -} - - -QColor GLWidget::hoverHaloColor() const { - return view_->hoverHaloColor(); -} - - -qreal GLWidget::hoverHaloFillAlpha() const { - return view_->hoverHaloFillAlpha(); -} - - -bool GLWidget::isSelectionHaloEnabled() const { - return view_->isSelectionHaloEnabled(); -} - - -QColor GLWidget::selectionHaloColor() const { - return view_->selectionHaloColor(); -} - - -qreal GLWidget::selectionHaloFillAlpha() const { - return view_->selectionHaloFillAlpha(); -} - - -void GLWidget::addObject(GLObjectBase * o) { - view_->addObject(o); -} - - -QByteArray GLWidget::saveCamera() { - return view_->saveCamera(); -} - - -void GLWidget::restoreCamera(const QByteArray &ba) { - view_->restoreCamera(ba); -} - - -void GLWidget::stop() { - view_->stop(); -} - - -void GLWidget::start(float freq, GLRendererBase * r) { - if (r == nullptr) r = new RendererSimple(view_); - GLRendererBase * pr = nullptr; - view_->setRenderer(r, &pr); - if (pr != nullptr && pr != r) delete pr; - view_->start(freq); -} - - -void GLWidget::setBackColor(const QColor & c) { - view_->setBackColor(c); -} - - -void GLWidget::setLineWidth(const qreal & arg) { - view_->setLineWidth(arg); -} - - -void GLWidget::setFOV(const qreal & arg) { - view_->setFOV(arg); -} - - -void GLWidget::setDepthStart(const qreal & arg) { - view_->setDepthStart(arg); -} - - -void GLWidget::setDepthEnd(const qreal & arg) { - view_->setDepthEnd(arg); -} - - -void GLWidget::setAmbientColor(const QColor & arg) { - view_->setAmbientColor(arg); -} - - -void GLWidget::setLightEnabled(const bool & arg) { - view_->setLightEnabled(arg); -} - - -void GLWidget::setGrabMouseEnabled(const bool & arg) { - view_->setGrabMouseEnabled(arg); -} - - -void GLWidget::setMouseRotateEnabled(const bool & arg) { - view_->setMouseRotateEnabled(arg); -} - - -void GLWidget::setMouseSelectionEnabled(const bool & arg) { - view_->setMouseSelectionEnabled(arg); -} - - -void GLWidget::setCameraOrbit(const bool & arg) { - view_->setCameraOrbit(arg); -} - - -void GLWidget::setHoverHaloEnabled(const bool & arg) { - view_->setHoverHaloEnabled(arg); -} - - -void GLWidget::setHoverHaloColor(const QColor & arg) { - view_->setHoverHaloColor(arg); -} - - -void GLWidget::setHoverHaloFillAlpha(const qreal & arg) { - view_->setHoverHaloFillAlpha(arg); -} - - -void GLWidget::setSelectionHaloEnabled(const bool & arg) { - view_->setSelectionHaloEnabled(arg); -} - - -void GLWidget::setSelectionHaloColor(const QColor & arg) { - view_->setSelectionHaloColor(arg); -} - - -void GLWidget::setSelectionHaloFillAlpha(const qreal & arg) { - view_->setSelectionHaloFillAlpha(arg); -} - - -void GLWidget::viewDoubleClicked() { -// qDebug() << "click widget!!"; - if (view_->windowState() == Qt::WindowFullScreen) { -// view_->hide(); - container = QWidget::createWindowContainer(view_, this); - lay->addWidget(container); - container->show(); -// show(); - } else { -// hide(); - view_->setParent(nullptr); - view_->showFullScreen(); - lay->removeWidget(container); - } -// qDebug() << "click widge done!"; -} +#include "glwidget.h" +#include "renderer_simple.h" +#include "renderer_deferred_shading.h" +#include + + +GLWidget::GLWidget(QWidget *parent) : QWidget(parent) { + view_ = new QGLView(); + view_->setFlags(windowFlags() | Qt::FramelessWindowHint); + container = QWidget::createWindowContainer(view_, this); + lay = new QVBoxLayout(this); + lay->addWidget(container); + lay->setContentsMargins(0, 0, 0, 0); + lay->setSpacing(0); + setMouseTracking(true); + setWindowIcon(QIcon("://icons/qglview.png")); + connect(view_, &QGLView::doubleClick, this, &GLWidget::viewDoubleClicked); +} + + +QColor GLWidget::backColor() const { + return view_->backColor(); +} + + +qreal GLWidget::lineWidth() const { + return view_->lineWidth(); +} + + +qreal GLWidget::FOV() const { + return view_->FOV(); +} + + +qreal GLWidget::depthStart() const { + return view_->depthStart(); +} + + +qreal GLWidget::depthEnd() const { + return view_->depthEnd(); +} + + +QColor GLWidget::ambientColor() const { + return view_->ambientColor(); +} + + +bool GLWidget::isLightEnabled() const { + return view_->isLightEnabled(); +} + + +bool GLWidget::isGrabMouseEnabled() const { + return view_->isGrabMouseEnabled(); +} + + +bool GLWidget::isMouseRotateEnabled() const { + return view_->isMouseRotateEnabled(); +} + + +bool GLWidget::isMouseSelectionEnabled() const { + return view_->isMouseSelectionEnabled(); +} + + +bool GLWidget::isCameraOrbit() const +{ + return view_->isCameraOrbit(); +} + + +bool GLWidget::isHoverHaloEnabled() const { + return view_->isHoverHaloEnabled(); +} + + +QColor GLWidget::hoverHaloColor() const { + return view_->hoverHaloColor(); +} + + +qreal GLWidget::hoverHaloFillAlpha() const { + return view_->hoverHaloFillAlpha(); +} + + +bool GLWidget::isSelectionHaloEnabled() const { + return view_->isSelectionHaloEnabled(); +} + + +QColor GLWidget::selectionHaloColor() const { + return view_->selectionHaloColor(); +} + + +qreal GLWidget::selectionHaloFillAlpha() const { + return view_->selectionHaloFillAlpha(); +} + + +void GLWidget::addObject(GLObjectBase * o) { + view_->addObject(o); +} + + +QByteArray GLWidget::saveCamera() { + return view_->saveCamera(); +} + + +void GLWidget::restoreCamera(const QByteArray &ba) { + view_->restoreCamera(ba); +} + + +void GLWidget::stop() { + view_->stop(); +} + + +void GLWidget::start(float freq, GLRendererBase * r) { + if (r == nullptr) r = new RendererSimple(view_); + GLRendererBase * pr = nullptr; + view_->setRenderer(r, &pr); + if (pr != nullptr && pr != r) delete pr; + view_->start(freq); +} + + +void GLWidget::setBackColor(const QColor & c) { + view_->setBackColor(c); +} + + +void GLWidget::setLineWidth(const qreal & arg) { + view_->setLineWidth(arg); +} + + +void GLWidget::setFOV(const qreal & arg) { + view_->setFOV(arg); +} + + +void GLWidget::setDepthStart(const qreal & arg) { + view_->setDepthStart(arg); +} + + +void GLWidget::setDepthEnd(const qreal & arg) { + view_->setDepthEnd(arg); +} + + +void GLWidget::setAmbientColor(const QColor & arg) { + view_->setAmbientColor(arg); +} + + +void GLWidget::setLightEnabled(const bool & arg) { + view_->setLightEnabled(arg); +} + + +void GLWidget::setGrabMouseEnabled(const bool & arg) { + view_->setGrabMouseEnabled(arg); +} + + +void GLWidget::setMouseRotateEnabled(const bool & arg) { + view_->setMouseRotateEnabled(arg); +} + + +void GLWidget::setMouseSelectionEnabled(const bool & arg) { + view_->setMouseSelectionEnabled(arg); +} + + +void GLWidget::setCameraOrbit(const bool & arg) { + view_->setCameraOrbit(arg); +} + + +void GLWidget::setHoverHaloEnabled(const bool & arg) { + view_->setHoverHaloEnabled(arg); +} + + +void GLWidget::setHoverHaloColor(const QColor & arg) { + view_->setHoverHaloColor(arg); +} + + +void GLWidget::setHoverHaloFillAlpha(const qreal & arg) { + view_->setHoverHaloFillAlpha(arg); +} + + +void GLWidget::setSelectionHaloEnabled(const bool & arg) { + view_->setSelectionHaloEnabled(arg); +} + + +void GLWidget::setSelectionHaloColor(const QColor & arg) { + view_->setSelectionHaloColor(arg); +} + + +void GLWidget::setSelectionHaloFillAlpha(const qreal & arg) { + view_->setSelectionHaloFillAlpha(arg); +} + + +void GLWidget::viewDoubleClicked() { +// qDebug() << "click widget!!"; + if (view_->windowState() == Qt::WindowFullScreen) { +// view_->hide(); + container = QWidget::createWindowContainer(view_, this); + lay->addWidget(container); + container->show(); +// show(); + } else { +// hide(); + view_->setParent(nullptr); + view_->showFullScreen(); + lay->removeWidget(container); + } +// qDebug() << "click widge done!"; +} diff --git a/qglview/glwidget.h b/libs/qglview/glwidget.h similarity index 97% rename from qglview/glwidget.h rename to libs/qglview/glwidget.h index 87eb6f1..1f8597e 100644 --- a/qglview/glwidget.h +++ b/libs/qglview/glwidget.h @@ -1,88 +1,88 @@ -#ifndef GLWIDGET_H -#define GLWIDGET_H - -#include - - -class QGLView; -class GLRendererBase; -class GLObjectBase; - -class GLWidget : public QWidget -{ - Q_OBJECT - Q_PROPERTY (QColor backColor READ backColor WRITE setBackColor) - Q_PROPERTY (qreal lineWidth READ lineWidth WRITE setLineWidth) - Q_PROPERTY (qreal FOV READ FOV WRITE setFOV) - Q_PROPERTY (qreal depthStart READ depthStart WRITE setDepthStart) - Q_PROPERTY (qreal depthEnd READ depthEnd WRITE setDepthEnd) - Q_PROPERTY (QColor ambientColor READ ambientColor WRITE setAmbientColor) - Q_PROPERTY (bool grabMouse READ isGrabMouseEnabled WRITE setGrabMouseEnabled) - Q_PROPERTY (bool mouseRotate READ isMouseRotateEnabled WRITE setMouseRotateEnabled) - Q_PROPERTY (bool mouseSelection READ isMouseSelectionEnabled WRITE setMouseSelectionEnabled) - Q_PROPERTY (bool cameraOrbit READ isCameraOrbit WRITE setCameraOrbit) - Q_PROPERTY (bool hoverHalo READ isHoverHaloEnabled WRITE setHoverHaloEnabled) - Q_PROPERTY (QColor hoverHaloColor READ hoverHaloColor WRITE setHoverHaloColor) - Q_PROPERTY (qreal hoverHaloFillAlpha READ hoverHaloFillAlpha WRITE setHoverHaloFillAlpha) - Q_PROPERTY (bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled) - Q_PROPERTY (QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor) - Q_PROPERTY (qreal selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha) -public: - explicit GLWidget(QWidget *parent = nullptr); - QGLView * view() {return view_;} - - QColor backColor() const; - qreal lineWidth() const; - qreal FOV() const; - qreal depthStart() const; - qreal depthEnd() const; - QColor ambientColor() const; - bool isLightEnabled() const; - bool isGrabMouseEnabled() const; - bool isMouseRotateEnabled() const; - bool isMouseSelectionEnabled() const; - bool isCameraOrbit() const; - bool isHoverHaloEnabled() const; - QColor hoverHaloColor() const; - qreal hoverHaloFillAlpha() const; - bool isSelectionHaloEnabled() const; - QColor selectionHaloColor() const; - qreal selectionHaloFillAlpha() const; - - void addObject(GLObjectBase * o); - QByteArray saveCamera(); - void restoreCamera(const QByteArray & ba); - -public slots: - void stop(); - void start(float freq = 60.0, GLRendererBase * r = nullptr); - void setBackColor(const QColor & c); - void setLineWidth(const qreal & arg); - void setFOV(const qreal & arg); - void setDepthStart(const qreal & arg); - void setDepthEnd(const qreal & arg); - void setAmbientColor(const QColor & arg); - void setLightEnabled(const bool & arg); - void setGrabMouseEnabled(const bool & arg); - void setMouseRotateEnabled(const bool & arg); - void setMouseSelectionEnabled(const bool & arg); - void setCameraOrbit(const bool & arg); - void setHoverHaloEnabled(const bool & arg); - void setHoverHaloColor(const QColor & arg); - void setHoverHaloFillAlpha(const qreal & arg); - void setSelectionHaloEnabled(const bool & arg); - void setSelectionHaloColor(const QColor & arg); - void setSelectionHaloFillAlpha(const qreal & arg); - -private slots: - void viewDoubleClicked(); - -private: - QWidget * container; - QGLView * view_; - QLayout * lay; - -signals: -}; - -#endif // GLWIDGET_H +#ifndef GLWIDGET_H +#define GLWIDGET_H + +#include + + +class QGLView; +class GLRendererBase; +class GLObjectBase; + +class GLWidget : public QWidget +{ + Q_OBJECT + Q_PROPERTY (QColor backColor READ backColor WRITE setBackColor) + Q_PROPERTY (qreal lineWidth READ lineWidth WRITE setLineWidth) + Q_PROPERTY (qreal FOV READ FOV WRITE setFOV) + Q_PROPERTY (qreal depthStart READ depthStart WRITE setDepthStart) + Q_PROPERTY (qreal depthEnd READ depthEnd WRITE setDepthEnd) + Q_PROPERTY (QColor ambientColor READ ambientColor WRITE setAmbientColor) + Q_PROPERTY (bool grabMouse READ isGrabMouseEnabled WRITE setGrabMouseEnabled) + Q_PROPERTY (bool mouseRotate READ isMouseRotateEnabled WRITE setMouseRotateEnabled) + Q_PROPERTY (bool mouseSelection READ isMouseSelectionEnabled WRITE setMouseSelectionEnabled) + Q_PROPERTY (bool cameraOrbit READ isCameraOrbit WRITE setCameraOrbit) + Q_PROPERTY (bool hoverHalo READ isHoverHaloEnabled WRITE setHoverHaloEnabled) + Q_PROPERTY (QColor hoverHaloColor READ hoverHaloColor WRITE setHoverHaloColor) + Q_PROPERTY (qreal hoverHaloFillAlpha READ hoverHaloFillAlpha WRITE setHoverHaloFillAlpha) + Q_PROPERTY (bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled) + Q_PROPERTY (QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor) + Q_PROPERTY (qreal selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha) +public: + explicit GLWidget(QWidget *parent = nullptr); + QGLView * view() {return view_;} + + QColor backColor() const; + qreal lineWidth() const; + qreal FOV() const; + qreal depthStart() const; + qreal depthEnd() const; + QColor ambientColor() const; + bool isLightEnabled() const; + bool isGrabMouseEnabled() const; + bool isMouseRotateEnabled() const; + bool isMouseSelectionEnabled() const; + bool isCameraOrbit() const; + bool isHoverHaloEnabled() const; + QColor hoverHaloColor() const; + qreal hoverHaloFillAlpha() const; + bool isSelectionHaloEnabled() const; + QColor selectionHaloColor() const; + qreal selectionHaloFillAlpha() const; + + void addObject(GLObjectBase * o); + QByteArray saveCamera(); + void restoreCamera(const QByteArray & ba); + +public slots: + void stop(); + void start(float freq = 60.0, GLRendererBase * r = nullptr); + void setBackColor(const QColor & c); + void setLineWidth(const qreal & arg); + void setFOV(const qreal & arg); + void setDepthStart(const qreal & arg); + void setDepthEnd(const qreal & arg); + void setAmbientColor(const QColor & arg); + void setLightEnabled(const bool & arg); + void setGrabMouseEnabled(const bool & arg); + void setMouseRotateEnabled(const bool & arg); + void setMouseSelectionEnabled(const bool & arg); + void setCameraOrbit(const bool & arg); + void setHoverHaloEnabled(const bool & arg); + void setHoverHaloColor(const QColor & arg); + void setHoverHaloFillAlpha(const qreal & arg); + void setSelectionHaloEnabled(const bool & arg); + void setSelectionHaloColor(const QColor & arg); + void setSelectionHaloFillAlpha(const qreal & arg); + +private slots: + void viewDoubleClicked(); + +private: + QWidget * container; + QGLView * view_; + QLayout * lay; + +signals: +}; + +#endif // GLWIDGET_H diff --git a/qad/icons/alpha.png b/libs/qglview/icons/alpha.png similarity index 100% rename from qad/icons/alpha.png rename to libs/qglview/icons/alpha.png diff --git a/kx_utils/icons/application-exit.png b/libs/qglview/icons/application-exit.png similarity index 100% rename from kx_utils/icons/application-exit.png rename to libs/qglview/icons/application-exit.png diff --git a/kx_utils/icons/configure.png b/libs/qglview/icons/configure.png similarity index 100% rename from kx_utils/icons/configure.png rename to libs/qglview/icons/configure.png diff --git a/kx_utils/icons/dialog-close.png b/libs/qglview/icons/dialog-close.png similarity index 100% rename from kx_utils/icons/dialog-close.png rename to libs/qglview/icons/dialog-close.png diff --git a/qglview/icons/document-import.png b/libs/qglview/icons/document-import.png similarity index 100% rename from qglview/icons/document-import.png rename to libs/qglview/icons/document-import.png diff --git a/qglview/icons/document-new.png b/libs/qglview/icons/document-new.png similarity index 100% rename from qglview/icons/document-new.png rename to libs/qglview/icons/document-new.png diff --git a/qglview/icons/document-open.png b/libs/qglview/icons/document-open.png similarity index 100% rename from qglview/icons/document-open.png rename to libs/qglview/icons/document-open.png diff --git a/qglview/icons/document-save-.png b/libs/qglview/icons/document-save-.png similarity index 100% rename from qglview/icons/document-save-.png rename to libs/qglview/icons/document-save-.png diff --git a/qglview/icons/document-save-all.png b/libs/qglview/icons/document-save-all.png similarity index 100% rename from qglview/icons/document-save-all.png rename to libs/qglview/icons/document-save-all.png diff --git a/kx_utils/icons/document-save.png b/libs/qglview/icons/document-save.png similarity index 100% rename from kx_utils/icons/document-save.png rename to libs/qglview/icons/document-save.png diff --git a/kx_utils/icons/edit-clear-locationbar-rtl.png b/libs/qglview/icons/edit-clear-locationbar-rtl.png similarity index 100% rename from kx_utils/icons/edit-clear-locationbar-rtl.png rename to libs/qglview/icons/edit-clear-locationbar-rtl.png diff --git a/kx_utils/icons/edit-clear.png b/libs/qglview/icons/edit-clear.png similarity index 100% rename from kx_utils/icons/edit-clear.png rename to libs/qglview/icons/edit-clear.png diff --git a/kx_utils/icons/edit-copy.png b/libs/qglview/icons/edit-copy.png similarity index 100% rename from kx_utils/icons/edit-copy.png rename to libs/qglview/icons/edit-copy.png diff --git a/kx_utils/icons/edit-delete.png b/libs/qglview/icons/edit-delete.png similarity index 100% rename from kx_utils/icons/edit-delete.png rename to libs/qglview/icons/edit-delete.png diff --git a/kx_utils/icons/edit-find.png b/libs/qglview/icons/edit-find.png similarity index 100% rename from kx_utils/icons/edit-find.png rename to libs/qglview/icons/edit-find.png diff --git a/kx_utils/icons/edit-guides.png b/libs/qglview/icons/edit-guides.png similarity index 100% rename from kx_utils/icons/edit-guides.png rename to libs/qglview/icons/edit-guides.png diff --git a/kx_utils/icons/edit-paste.png b/libs/qglview/icons/edit-paste.png similarity index 100% rename from kx_utils/icons/edit-paste.png rename to libs/qglview/icons/edit-paste.png diff --git a/qad/icons/item-add.png b/libs/qglview/icons/item-add.png similarity index 100% rename from qad/icons/item-add.png rename to libs/qglview/icons/item-add.png diff --git a/qad/icons/item.png b/libs/qglview/icons/item.png similarity index 100% rename from qad/icons/item.png rename to libs/qglview/icons/item.png diff --git a/kx_utils/icons/list-add.png b/libs/qglview/icons/list-add.png similarity index 100% rename from kx_utils/icons/list-add.png rename to libs/qglview/icons/list-add.png diff --git a/qad/icons/node-add.png b/libs/qglview/icons/node-add.png similarity index 100% rename from qad/icons/node-add.png rename to libs/qglview/icons/node-add.png diff --git a/qad/icons/node.png b/libs/qglview/icons/node.png similarity index 100% rename from qad/icons/node.png rename to libs/qglview/icons/node.png diff --git a/qglengine/icons/qglview.png b/libs/qglview/icons/qglview.png similarity index 100% rename from qglengine/icons/qglview.png rename to libs/qglview/icons/qglview.png diff --git a/qglengine/icons/qglview.xcf b/libs/qglview/icons/qglview.xcf similarity index 100% rename from qglengine/icons/qglview.xcf rename to libs/qglview/icons/qglview.xcf diff --git a/qglview/icons/type-camera.png b/libs/qglview/icons/type-camera.png similarity index 100% rename from qglview/icons/type-camera.png rename to libs/qglview/icons/type-camera.png diff --git a/qglview/icons/type-geo.png b/libs/qglview/icons/type-geo.png similarity index 100% rename from qglview/icons/type-geo.png rename to libs/qglview/icons/type-geo.png diff --git a/qglview/icons/type-light.png b/libs/qglview/icons/type-light.png similarity index 100% rename from qglview/icons/type-light.png rename to libs/qglview/icons/type-light.png diff --git a/kx_utils/icons/view-grid.png b/libs/qglview/icons/view-grid.png similarity index 100% rename from kx_utils/icons/view-grid.png rename to libs/qglview/icons/view-grid.png diff --git a/kx_utils/icons/zoom-fit-best.png b/libs/qglview/icons/zoom-fit-best.png similarity index 100% rename from kx_utils/icons/zoom-fit-best.png rename to libs/qglview/icons/zoom-fit-best.png diff --git a/qglview/loader_3ds.cpp b/libs/qglview/loader_3ds.cpp similarity index 100% rename from qglview/loader_3ds.cpp rename to libs/qglview/loader_3ds.cpp diff --git a/qglview/loader_3ds.h b/libs/qglview/loader_3ds.h similarity index 100% rename from qglview/loader_3ds.h rename to libs/qglview/loader_3ds.h diff --git a/qglview/loader_ase.cpp b/libs/qglview/loader_ase.cpp similarity index 100% rename from qglview/loader_ase.cpp rename to libs/qglview/loader_ase.cpp diff --git a/qglview/loader_ase.h b/libs/qglview/loader_ase.h similarity index 100% rename from qglview/loader_ase.h rename to libs/qglview/loader_ase.h diff --git a/qglview/loader_dae.cpp b/libs/qglview/loader_dae.cpp similarity index 100% rename from qglview/loader_dae.cpp rename to libs/qglview/loader_dae.cpp diff --git a/qglview/loader_dae.h b/libs/qglview/loader_dae.h similarity index 100% rename from qglview/loader_dae.h rename to libs/qglview/loader_dae.h diff --git a/qglview/loader_obj.cpp b/libs/qglview/loader_obj.cpp similarity index 100% rename from qglview/loader_obj.cpp rename to libs/qglview/loader_obj.cpp diff --git a/qglview/loader_obj.h b/libs/qglview/loader_obj.h similarity index 100% rename from qglview/loader_obj.h rename to libs/qglview/loader_obj.h diff --git a/qglview/loader_qgl.cpp b/libs/qglview/loader_qgl.cpp similarity index 100% rename from qglview/loader_qgl.cpp rename to libs/qglview/loader_qgl.cpp diff --git a/qglview/loader_qgl.h b/libs/qglview/loader_qgl.h similarity index 100% rename from qglview/loader_qgl.h rename to libs/qglview/loader_qgl.h diff --git a/qglview/material_editor.cpp b/libs/qglview/material_editor.cpp similarity index 100% rename from qglview/material_editor.cpp rename to libs/qglview/material_editor.cpp diff --git a/qglview/material_editor.h b/libs/qglview/material_editor.h similarity index 100% rename from qglview/material_editor.h rename to libs/qglview/material_editor.h diff --git a/qglview/material_editor.ui b/libs/qglview/material_editor.ui similarity index 100% rename from qglview/material_editor.ui rename to libs/qglview/material_editor.ui diff --git a/qglview/material_map_editor.cpp b/libs/qglview/material_map_editor.cpp similarity index 100% rename from qglview/material_map_editor.cpp rename to libs/qglview/material_map_editor.cpp diff --git a/qglview/material_map_editor.h b/libs/qglview/material_map_editor.h similarity index 100% rename from qglview/material_map_editor.h rename to libs/qglview/material_map_editor.h diff --git a/qglview/material_map_editor.ui b/libs/qglview/material_map_editor.ui similarity index 100% rename from qglview/material_map_editor.ui rename to libs/qglview/material_map_editor.ui diff --git a/qglview/openglwindow.cpp b/libs/qglview/openglwindow.cpp similarity index 95% rename from qglview/openglwindow.cpp rename to libs/qglview/openglwindow.cpp index 375d1fa..cb3bc2a 100644 --- a/qglview/openglwindow.cpp +++ b/libs/qglview/openglwindow.cpp @@ -1,96 +1,96 @@ -#include "openglwindow.h" -#include -#include -#include -#include -#include - - -OpenGLWindow::OpenGLWindow(QWindow *parent) - : QWindow(parent) - , m_context(nullptr) - , m_device(nullptr) -{ - setFlags(flags() | Qt::FramelessWindowHint); - setSurfaceType(QWindow::OpenGLSurface); - QSurfaceFormat format = QSurfaceFormat::defaultFormat(); -// qDebug() << format; -#ifdef QT_OPENGL_ES_2 - format.setRenderableType(QSurfaceFormat::OpenGLES); -#else - if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) { - format.setVersion(2, 0); - format.setProfile(QSurfaceFormat::NoProfile); - } -#endif - format.setDepthBufferSize(24); - format.setSamples(8); -// format.setStencilBufferSize(8); - setFormat(format); - QSurfaceFormat::setDefaultFormat(format); -} - - -OpenGLWindow::~OpenGLWindow() { - delete m_device; -} - - -void OpenGLWindow::render(QPainter *painter) { -} - - -void OpenGLWindow::initialize() { -} - - -void OpenGLWindow::render() { -// if (!m_device) m_device = new QOpenGLPaintDevice; -// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); -// m_device->setSize(size() * devicePixelRatio()); -// m_device->setDevicePixelRatio(devicePixelRatio()); -// QPainter painter(m_device); -// render(&painter); -} - - -void OpenGLWindow::renderLater() { - requestUpdate(); -} - - -bool OpenGLWindow::event(QEvent *event) { - switch (event->type()) { - case QEvent::UpdateRequest: - renderNow(); - return true; - default: - return QWindow::event(event); - } -} - - -void OpenGLWindow::exposeEvent(QExposeEvent *event) { - if (isExposed()) renderNow(); -} - - -void OpenGLWindow::renderNow() { - if (!isExposed()) - return; - bool needsInitialize = false; - if (!m_context) { - m_context = new QOpenGLContext(this); - m_context->setFormat(requestedFormat()); - m_context->create(); - needsInitialize = true; - } - m_context->makeCurrent(this); - if (needsInitialize) { - initializeOpenGLFunctions(); - initialize(); - } - render(); - m_context->swapBuffers(this); -} - +#include "openglwindow.h" +#include +#include +#include +#include +#include + + +OpenGLWindow::OpenGLWindow(QWindow *parent) + : QWindow(parent) + , m_context(nullptr) + , m_device(nullptr) +{ + setFlags(flags() | Qt::FramelessWindowHint); + setSurfaceType(QWindow::OpenGLSurface); + QSurfaceFormat format = QSurfaceFormat::defaultFormat(); +// qDebug() << format; +#ifdef QT_OPENGL_ES_2 + format.setRenderableType(QSurfaceFormat::OpenGLES); +#else + if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) { + format.setVersion(2, 0); + format.setProfile(QSurfaceFormat::NoProfile); + } +#endif + format.setDepthBufferSize(24); + format.setSamples(8); +// format.setStencilBufferSize(8); + setFormat(format); + QSurfaceFormat::setDefaultFormat(format); +} + + +OpenGLWindow::~OpenGLWindow() { + delete m_device; +} + + +void OpenGLWindow::render(QPainter *painter) { +} + + +void OpenGLWindow::initialize() { +} + + +void OpenGLWindow::render() { +// if (!m_device) m_device = new QOpenGLPaintDevice; +// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); +// m_device->setSize(size() * devicePixelRatio()); +// m_device->setDevicePixelRatio(devicePixelRatio()); +// QPainter painter(m_device); +// render(&painter); +} + + +void OpenGLWindow::renderLater() { + requestUpdate(); +} + + +bool OpenGLWindow::event(QEvent *event) { + switch (event->type()) { + case QEvent::UpdateRequest: + renderNow(); + return true; + default: + return QWindow::event(event); + } +} + + +void OpenGLWindow::exposeEvent(QExposeEvent *event) { + if (isExposed()) renderNow(); +} + + +void OpenGLWindow::renderNow() { + if (!isExposed()) + return; + bool needsInitialize = false; + if (!m_context) { + m_context = new QOpenGLContext(this); + m_context->setFormat(requestedFormat()); + m_context->create(); + needsInitialize = true; + } + m_context->makeCurrent(this); + if (needsInitialize) { + initializeOpenGLFunctions(); + initialize(); + } + render(); + m_context->swapBuffers(this); +} + diff --git a/qglview/openglwindow.h b/libs/qglview/openglwindow.h similarity index 94% rename from qglview/openglwindow.h rename to libs/qglview/openglwindow.h index 6816665..504028c 100644 --- a/qglview/openglwindow.h +++ b/libs/qglview/openglwindow.h @@ -1,36 +1,36 @@ -#include -#include - -class QPainter; -class QOpenGLContext; -class QOpenGLPaintDevice; - - -class OpenGLWindow : public QWindow, protected QOpenGLFunctions -{ - Q_OBJECT -public: - explicit OpenGLWindow(QWindow *parent = nullptr); - ~OpenGLWindow(); - - virtual void render(QPainter *painter); - virtual void render(); - - virtual void initialize(); - - QOpenGLContext * context() {return m_context;} - -public slots: - void renderLater(); - void renderNow(); - -protected: - bool event(QEvent *event) override; - - void exposeEvent(QExposeEvent *event) override; - -private: - QOpenGLContext *m_context; - QOpenGLPaintDevice *m_device; -}; - +#include +#include + +class QPainter; +class QOpenGLContext; +class QOpenGLPaintDevice; + + +class OpenGLWindow : public QWindow, protected QOpenGLFunctions +{ + Q_OBJECT +public: + explicit OpenGLWindow(QWindow *parent = nullptr); + ~OpenGLWindow(); + + virtual void render(QPainter *painter); + virtual void render(); + + virtual void initialize(); + + QOpenGLContext * context() {return m_context;} + +public slots: + void renderLater(); + void renderNow(); + +protected: + bool event(QEvent *event) override; + + void exposeEvent(QExposeEvent *event) override; + +private: + QOpenGLContext *m_context; + QOpenGLPaintDevice *m_device; +}; + diff --git a/qglview/plugin/CMakeLists.txt b/libs/qglview/plugin/CMakeLists.txt similarity index 98% rename from qglview/plugin/CMakeLists.txt rename to libs/qglview/plugin/CMakeLists.txt index 2fd203c..4245507 100644 --- a/qglview/plugin/CMakeLists.txt +++ b/libs/qglview/plugin/CMakeLists.txt @@ -1 +1 @@ -_qt_plugin(qglview "Gui;Widgets;OpenGL" "qglview") +_qt_plugin(qglview "Gui;Widgets;OpenGL" "qglview") diff --git a/qglengine/plugin/qglview_designerplugin.cpp b/libs/qglview/plugin/qglview_designerplugin.cpp similarity index 100% rename from qglengine/plugin/qglview_designerplugin.cpp rename to libs/qglview/plugin/qglview_designerplugin.cpp diff --git a/qglengine/plugin/qglview_designerplugin.h b/libs/qglview/plugin/qglview_designerplugin.h similarity index 100% rename from qglengine/plugin/qglview_designerplugin.h rename to libs/qglview/plugin/qglview_designerplugin.h diff --git a/qglview/plugin/qglviewplugin.cpp b/libs/qglview/plugin/qglviewplugin.cpp similarity index 100% rename from qglview/plugin/qglviewplugin.cpp rename to libs/qglview/plugin/qglviewplugin.cpp diff --git a/qglengine/plugin/qglviewplugin.h b/libs/qglview/plugin/qglviewplugin.h similarity index 100% rename from qglengine/plugin/qglviewplugin.h rename to libs/qglview/plugin/qglviewplugin.h diff --git a/qglview/propertyeditor.cpp b/libs/qglview/propertyeditor.cpp similarity index 100% rename from qglview/propertyeditor.cpp rename to libs/qglview/propertyeditor.cpp diff --git a/qglview/propertyeditor.h b/libs/qglview/propertyeditor.h similarity index 100% rename from qglview/propertyeditor.h rename to libs/qglview/propertyeditor.h diff --git a/qglview/qglview.cpp b/libs/qglview/qglview.cpp similarity index 96% rename from qglview/qglview.cpp rename to libs/qglview/qglview.cpp index 74adf53..1878a40 100644 --- a/qglview/qglview.cpp +++ b/libs/qglview/qglview.cpp @@ -1,846 +1,846 @@ -/* - QGLView - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "qglview.h" - -#include -#include - - -QGLView::QGLView(): OpenGLWindow(), fbo_selection(3) { -// setFrameShape(QFrame::NoFrame); -// setViewportUpdateMode(FullViewportUpdate); -// setCacheMode(CacheNone); -// setMouseTracking(true); -// setFocusPolicy(Qt::WheelFocus); -// setScene(new QGraphicsScene()); -// setInteractive(true); - setIcon(QIcon("://icons/qglview.png")); - deleting_ = false; - timer = 0; - need_init_ = is_first_draw = true; - objects_.is_root = true; - objects_.view_ = this; - backColor_ = Qt::darkGray; - hoverHaloColor_ = QColor(195, 140, 255, 96); - selectionHaloColor_ = QColor(175, 255, 140); - ambientColor_ = QColor(10, 10, 10); - lastPos = QPoint(-1, -1); - lineWidth_ = 1.; - max_anisotropic = 1; - max_texture_chanels = 8; - cameraOrbit_ = lightEnabled_ = true; - shaders_supported = selecting_ = customMouseMove_ = false; - sel_button = Qt::LeftButton; - sel_mod = Qt::NoModifier; - renderer_ = nullptr; - fps_cnt = 0; - fps_tm = fps_ = 0.; - sel_obj = hov_obj = nullptr; - fogDensity_ = fogEnd_ = 1.; - fogStart_ = 0.; - fogMode_ = Exp; - hoverHaloFill_ = 0.333f; - selectionHaloFill_ = 0.5f; - //lmode = Simple; - shader_select = shader_halo = nullptr; - setFeature(qglMSAA, false); - setFeature(qglFXAA, false); - setFeature(qglLinearFiltering, true); - setFeature(qglAnisotropicLevel, 8); - setFeature(qglHDR, false); - setFeature(qglEyeAccomodationEnabled, false); - setFeature(qglEyeAccomodationTime, 16.); - setFeature(qglEyeAccomodationMaxSpeed, 0.2); - setFeature(qglBloomEnabled, false); - setFeature(qglBloomThreshold, 0.9); - setFeature(qglBloomFactor, 1.); - setFeature(qglBloomRadius, 8); - setFeature(qglMotionBlurEnabled, false); - setFeature(qglMotionBlurFactor, 1.); - setFeature(qglMotionBlurSteps, 8); - setFeature(qglShadowsEnabled, false); - setFeature(qglShadowsMapSize, 512); - setFeature(qglShadowsSoftEnabled, true); - setFeature(qglReflectionsEnabled, false); - setFeature(qglReflectionsBlur, true); - setFeature(qglSSAOEnabled, false); - setFeature(qglSSAORadius, 5); - setFeature(qglDepthOfFieldEnabled, false); - setFeature(qglDepthOfFieldAutoFocusEnabled, true); - setFeature(qglDepthOfFieldAutoFocusSpeed, 0.1); - setFeature(qglDepthOfFieldFocus, 1.); - setFeature(qglDepthOfFieldDiaphragm, 8.); - mouse_first = mouseSelect_ = hoverHalo_ = selectionHalo_ = true; - mouseRotate_ = true; - fogEnabled_ = is_init = grabMouse_ = shaders_bind = changed_ = false; - rmode = GLObjectBase::Fill; - sel_mode = QGLView::SingleSelection; -// sel_pen = QPen(Qt::black, 1, Qt::DashLine); -// sel_brush = QBrush(QColor(170, 100, 255, 120)); - camera()->setAim(QVector3D()); - camera()->setPos(QVector3D(2, 2, 2)); - camera()->setName("Camera"); - addObject(camera()); - emit cameraPosChanged(camera()->pos()); - //camera().aim_ = camera().pos_; - ktm_.restart(); -} - - -QGLView::~QGLView() { - stop(); - if (shader_select) delete shader_select; - if (shader_halo) delete shader_halo; - deleting_ = true; -} - - -void QGLView::stop() { - if (timer) killTimer(timer); - timer = 0; -} - - -void QGLView::start(float freq) { - stop(); - timer = startTimer(freq <= 0.f ? 0 : int(1000.f / freq)); -} - - -GLRendererBase * QGLView::renderer() { - return renderer_; -} - - -void QGLView::setRenderer(GLRendererBase * r, GLRendererBase ** prev) { - if (prev != nullptr) *prev = renderer_; - renderer_ = r; -} - - -void QGLView::addObject(GLObjectBase * o) { - objects_.addChild(o); - o->setView(this); - collectLights(); - QList cl = o->children(true); - cl << o; - foreach (GLObjectBase * i, cl) { - emit objectAdded(i); - } - if (is_init) { - o->init(); - } -} - - -int QGLView::objectsCount(bool all) { - if (!all) return objects_.childCount(); - int cnt = 0; - objectsCountInternal(&cnt, &objects_); - return cnt; -} - - -void QGLView::removeObject(GLObjectBase * o, bool inChildren) { - o->setView(nullptr); - if (inChildren) - removeObjectInternal(o, &objects_); - else - objects_.removeChild(o); - objectDeleted(o); -} - - -void QGLView::removeObject(GLObjectBase & o, bool inChildren) { - removeObject(&o, inChildren); -} - - -void QGLView::clearObjects(bool deleteAll) { - removeObject(camera_); - objects_.clearChildren(deleteAll); - addObject(camera()); - selectObject(nullptr); - hov_obj = nullptr; -} - - -QList QGLView::objects(bool all) { - return objects_.children(all); -} - - -int QGLView::lightsCount() const { - return lights_.size(); -} - - -void QGLView::removeLight(int index) { - removeObject(lights_.at(index)); - lights_.removeAt(index); -} - - -void QGLView::removeLight(Light * l) { - foreach (Light * i, lights_) - if (i == l) removeObject(i); - lights_.removeAll(l); -} - - -void QGLView::clearLights(bool deleteAll) { - if (deleteAll) - foreach (Light * i, lights_) delete i; - lights_.clear(); -} - - -void QGLView::addTexture(const QString & path) { - textures_manager->addTexture(path); -} - - -void QGLView::addAnimation(const QString & dir, const QString & name) { - textures_manager->addAnimation(dir, name); -} - - -Light * QGLView::light(int index) { - return lights_[index]; -} - - -Light * QGLView::light(const QString & name) { - foreach (Light * i, lights_) - if (i->name_ == name) return i; - return nullptr; -} - - -void QGLView::selectObject(GLObjectBase * o) { - if (o == sel_obj) return; - GLObjectBase * pso = sel_obj; - sel_obj = o; - emit selectionChanged(sel_obj, pso); -} - - -void QGLView::resizeEvent(QResizeEvent * e) { - renderLater(); -} - -void QGLView::timerEvent(QTimerEvent *) { - renderNow(); - if (ktm_.elapsed() < QApplication::keyboardInputInterval()) return; - Qt::KeyboardModifiers km = QApplication::keyboardModifiers(); - foreach (int i, keys_) - emit keyEvent((Qt::Key)i, km); -} - - -void QGLView::render() { - if (!isVisible()) return; - resizeGL(width(), height()); - QRect g_rect(QPoint(), size()); - emit glBeforePaint(); - //qDebug() << "paintGL"; - //QMutexLocker ml_v(&v_mutex); - glEnable(GL_CULL_FACE); - //glDisable(GL_CULL_FACE); - camera()->apply(aspect); - //objects_.preparePos(camera()); - start_rp.cam_offset_matrix = camera()->offsetMatrix(); - start_rp.proj_matrix = getGLMatrix(GL_PROJECTION_MATRIX); - start_rp.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX); - //objects_.buildTransform(); - - /// Selection detect - //glClearFramebuffer(QColor(100, 0, 0, 0)); - if (mouseSelect_) { - glReleaseTextures(); - glEnableDepth(); - glDisable(GL_TEXTURE_1D); - glDisable(GL_TEXTURE_2D); - glDisable(GL_TEXTURE_CUBE_MAP); - glDisable(GL_MULTISAMPLE); - glDisable(GL_LIGHTING); - glDisable(GL_BLEND); - glDisable(GL_ALPHA_TEST); - glDisable(GL_RESCALE_NORMAL); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - fbo_selection.bind(); - fbo_selection.setWriteBuffer(0); - glClearFramebuffer(QColor(0, 0, 0, 0)); - if (shaders_supported && shader_select->isLinked()) shader_select->bind(); - renderSelection(); - if (shaders_supported && shader_select->isLinked()) shader_select->release(); - uchar cgid[4] = {0, 0, 0, 0}; - uint iid = 0; - GLObjectBase * so = nullptr; - if (!g_rect.contains(lastPos)) { - if (hov_obj != nullptr) { - hov_obj = nullptr; - emit hoverChanged(nullptr, hov_obj); - } - } else { - glReadPixels(lastPos.x(), height() - lastPos.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, cgid); - iid = uint(cgid[0] << 24) | uint(cgid[1] << 16) | uint(cgid[2] << 8) | cgid[3]; - so = ids.value(iid, nullptr); - //qDebug() <name() << cgid[3]; - } - if (selectionHalo_ && sel_obj) { - fbo_selection.setWriteBuffer(2); - renderHalo(sel_obj, qHash((quint64)sel_obj), selectionHaloColor_, selectionHaloFill_); - } - if (hoverHalo_ && hov_obj) { - fbo_selection.setWriteBuffer(1); - renderHalo(hov_obj, iid, hoverHaloColor_, hoverHaloFill_); - } - fbo_selection.release(); - glEnableDepth(); - /*glEnableClientState(GL_NORMAL_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnableClientState(GL_COLOR_ARRAY);*/ - } - - camera()->apply(aspect); - start_rp.cam_offset_matrix = camera()->offsetMatrix(); - cur_mvpm = start_rp.proj_matrix * start_rp.view_matrix * start_rp.cam_offset_matrix; - //objects_.preparePos(camera()); - - static GLRendererBase * prev_rend = nullptr; - glShadeModel(GL_SMOOTH); - if (prev_rend != renderer_) { - prev_rend = renderer_; - if (renderer_ != nullptr) { - renderer_->init(width(), height()); - renderer_->resize(width(), height()); - renderer_->reloadShaders(); - } - } - emit glBeginPaint(); - if (renderer_ != nullptr) { - renderer_->rp.prepare(); - renderer_->prepareScene(); - renderer_->renderScene(); - } - emit glPainting(); - glUseProgram(0); - if (selectionHalo_ || hoverHalo_) { - glReleaseTextures(); - glBindFramebuffer(GL_FRAMEBUFFER, 0); - - //glClearFramebuffer(Qt::black, false); - - glActiveTexture(GL_TEXTURE0); - glEnable(GL_BLEND); - glDisable(GL_TEXTURE_CUBE_MAP); - glDisable(GL_LIGHTING); - glDisableDepth(); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - if (selectionHalo_ && sel_obj) { - glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture(2)); - //qDebug() << "draw sel"; - glDrawQuad(); - } - if (hoverHalo_ && hov_obj) { - glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture(1)); - //qDebug() << "draw hover"; - //glBindTexture(GL_TEXTURE_2D, textures_manager->loadTexture("batt_pn.jpg")); - glDrawQuad(); - } - } - - glResetAllTransforms(); - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glUseProgram(0); - - //glDisable(GL_BLEND); - //glDisable(GL_LIGHTING); - //glActiveTexture(GL_TEXTURE0); - //glBindTexture(GL_TEXTURE_2D, textures_manager->loadTexture("batt_pn.jpg")); - //glDrawQuad(); - - emit glEndPaint(); - - /*releaseShaders(); - glActiveTextureChannel(0); - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_LIGHTING); - glDisable(GL_DEPTH_TEST); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(0.3, 0.5, 0.8, 0.5); - glResetAllTransforms(); - glBegin(GL_QUADS); - glTexCoord2f(0.f, 0.f); glVertex2f(-1.f, -1.f); - glTexCoord2f(1.f, 0.f); glVertex2f(1.f, -1.); - glTexCoord2f(1.f, 1.f); glVertex2f(1.f, 1.f); - glTexCoord2f(0.f, 1.f); glVertex2f(-1.f, 1.f); - glEnd();*/ - /* - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glDisable(GL_LIGHTING); - glActiveTextureChannel(0); - glBindTexture(GL_TEXTURE_2D, fbo->texture()); - glDisable(GL_DEPTH_TEST); - glBegin(GL_QUADS); - glColor3f(1.f, 1.f, 1.f); - glTexCoord2f(0.f, 0.f); glVertex2f(-1.f, -1.f); - glTexCoord2f(0.f, 1.f); glVertex2f(-1.f, 1.f); - glTexCoord2f(1.f, 1.f); glVertex2f(1.f, 1.f); - glTexCoord2f(1.f, 0.f); glVertex2f(1.f, -1.); - glEnd(); - glEnable(GL_DEPTH_TEST);*/ - fps_tm += time.elapsed(); - time.restart(); - fps_cnt++; - if (fps_tm < 1000.) return; - fps_ = fps_cnt / fps_tm * 1000.; - fps_tm = 0.; - fps_cnt = 0; -} - - -void QGLView::initialize() { - //initializeOpenGLFunctions(); - glEnable(GL_TEXTURE_MAX_ANISOTROPY_EXT); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glEnableDepth(); - glEnable(GL_CULL_FACE); - glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); - glActiveTexture(GL_TEXTURE0 + 3); - glEnable(GL_TEXTURE_GEN_S); - glEnable(GL_TEXTURE_GEN_T); - glEnable(GL_TEXTURE_GEN_R); - glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); - glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); - glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); - glActiveTexture(GL_TEXTURE0); - glShadeModel(GL_SMOOTH); - glCullFace(GL_BACK); - glEnable(GL_COLOR_MATERIAL); - glColorMaterial(GL_FRONT, GL_DIFFUSE); - - textures_manager->loadTextures(); - objects_.initInternal(); - checkCaps(); - - shader_select = new QOpenGLShaderProgram(context()); - shader_halo = new QOpenGLShaderProgram(context()); - reloadThisShaders(); - is_init = true; - //resizeGL(width(), height()); - need_init_ = false; - emit glInitializeDone(); -} - - -void QGLView::renderHalo(const GLObjectBase * obj, const uint iid, const QColor & color, const float & fill) { - if (!shaders_supported) return; - if (!shader_halo) return; - if (!shader_halo->isLinked()) return; - if (obj) { - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture()); - shader_halo->bind(); - shader_halo->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4()); - shader_halo->setUniformValue("t0", 0); - shader_halo->setUniformValue("dt", QVector2D(1.f / width(), 1.f / height())); - shader_halo->setUniformValue("selected", QVector4D(float((iid >> 24) & 0xFF) / 255.f, - float((iid >> 16) & 0xFF) / 255.f, - float((iid >> 8) & 0xFF) / 255.f, - float( iid & 0xFF) / 255.f)); - shader_halo->setUniformValue("color", color); - shader_halo->setUniformValue("fill", GLfloat(fill)); - //qDebug() << "render halo" << iid << shader_halo->log() << shader_halo->programId(); - glDisableDepth(); - //glClearFramebuffer(color); - glDrawQuad(shader_halo); - glDepthMask(GL_TRUE); - //glFlush(); - shader_halo->release(); - } else { - glClearFramebuffer(Qt::black, false); - } -} - - -void QGLView::renderSelection() { -// cid = 1; - ids.clear(); - if (shaders_supported) { - if (shader_select) { - if (shader_select->isLinked()) { - sh_id_loc = shader_select->uniformLocation("id"); - shader_select->setUniformValue("z_far", GLfloat(depthEnd())); - shader_select->setUniformValue("z_near", GLfloat(depthStart())); - } - } - } - //qDebug() << sh_id_loc; - start_rp.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX); - glPushMatrix(); - renderSingleSelection(objects_); - glPopMatrix(); -} - - -void QGLView::renderSingleSelection(GLObjectBase & o) { - if (!o.isInit()) { - o.init(); - o.loadTextures(); - } - if (!o.visible_ || !o.select_) return; - QMatrix4x4 curview = start_rp.view_matrix * start_rp.cam_offset_matrix * o.itransform_; - uint id = qHash((quint64)&o); - ids.insert(id, &o); - glLineWidth(o.line_width > 0.f ? o.line_width : lineWidth_); - glPointSize(o.line_width > 0.f ? o.line_width : lineWidth_); - if (shaders_supported){ - if (shader_select) { - if (shader_select->isLinked()) { - setUniformMatrices(shader_select, start_rp.proj_matrix, curview); - shader_select->setUniformValue(sh_id_loc, QVector4D(float((id >> 24) & 0xFF) / 255.f, - float((id >> 16) & 0xFF) / 255.f, - float((id >> 8) & 0xFF) / 255.f, - float(id & 0xFF) / 255.f)); - } - } - } else { - setGLMatrix(curview); - glColor4f(float((id >> 24) & 0xFF) / 255.f, - float((id >> 16) & 0xFF) / 255.f, - float((id >> 8) & 0xFF) / 255.f, - float(id & 0xFF) / 255.f); - } - //qDebug() << o.name() << "assign to" << sh_id_loc << cid; - //glColor4f(float((cid >> 24) & 0xFF) / 255.f, float((cid >> 16) & 0xFF) / 255.f, float((cid >> 8) & 0xFF) / 255.f, float(cid & 0xFF) / 255.f); -// ++cid; - o.draw(nullptr, true); - foreach (GLObjectBase * i, o.children_) - renderSingleSelection(*i); -} - - -void QGLView::collectLights() { - lights_.clear(); - collectObjectLights(&objects_); -} - - -void QGLView::objectDeleted(GLObjectBase * o) { - if (deleting_) return; - //qDebug() << "del" << o; - if (sel_obj == o) selectObject(nullptr); - if (hov_obj == o) hov_obj = nullptr; - collectLights(); -} - - -void QGLView::collectObjectLights(GLObjectBase * o) { - if (o->type_ == GLObjectBase::glLight) { - lights_ << globject_cast(o); - o->view_ = this; - } - foreach (GLObjectBase * i, o->children()) - collectObjectLights(i); -} - - -void QGLView::objectsCountInternal(int * cnt, GLObjectBase * where) { - ++(*cnt); - foreach (GLObjectBase * i, where->children_) - objectsCountInternal(cnt, i); -} - - -void QGLView::removeObjectInternal(GLObjectBase * o, GLObjectBase * where) { - foreach (GLObjectBase * i, where->children_) { - if (o == i) - where->removeChild(i); - else - removeObjectInternal(o, i); - objectDeleted(i); - } -} - - -void QGLView::checkCaps() { - glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropic); - //glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_chanels); - //qDebug() << max_texture_chanels; - //qDebug() << max_texture_chanels; - shaders_supported = QOpenGLShaderProgram::hasOpenGLShaderPrograms(); -} - - -void QGLView::reloadThisShaders() { - if (!shaders_supported) return; - loadShaders(shader_select, "selection", "://shaders"); - loadShaders(shader_halo, "selection_halo", "://shaders"); - //loadShaders(shader_rope, "rope", "://shaders"); -} - -void QGLView::glReleaseTextures(int channels) { - for (int i = channels - 1; i >= 0; --i) { - glActiveTexture(GL_TEXTURE0 + i); - glBindTexture(GL_TEXTURE_2D, 0); - glBindTexture(GL_TEXTURE_CUBE_MAP, 0); - } -} - - -void QGLView::applyFog() { - GLfloat fog_col[4] = {float(fogColor_.redF()), float(fogColor_.greenF()), float(fogColor_.blueF()), .0f}; - if (fogEnabled_) { - glEnable(GL_FOG); - glFogf(GL_FOG_DENSITY, fogDensity_); - glFogf(GL_FOG_START, fogStart_); - glFogf(GL_FOG_END, fogEnd_); - glFogi(GL_FOG_MODE, fogMode_); - fog_col[0] = fogColor_.redF(); - fog_col[1] = fogColor_.greenF(); - fog_col[2] = fogColor_.blueF(); - glFogfv(GL_FOG_COLOR, fog_col); - } else glDisable(GL_FOG); -} - - -void QGLView::resizeGL(int width, int height) { - if (!is_init) return; - if (width <= 0 || height <= 0) return; - if (prev_size == QSize(width, height)) return; - prev_size = QSize(width, height); - aspect = float(width) / float(height); - if (renderer_) renderer_->resize(width, height); - mouse_first = true; - //qDebug() << "resize" << width << height; - fbo_selection.resize(width, height); - iaspect = (aspect == 0.f) ? 0. : 1 / aspect; - glViewport(0, 0, width, height); - emit glResize(width, height); -} - - -void QGLView::mouseReleaseEvent(QMouseEvent * e) { -// qDebug() << "mouseReleaseEvent" << e << isActive(); -// QGraphicsView::mouseReleaseEvent(e); - //setCursor(QCursor(Qt::ArrowCursor)); - selecting_ = false; - if (mouseSelect_ && e->button() == Qt::LeftButton) { - if ((lastPos - downPos).manhattanLength() < 8) { - if (sel_obj != hov_obj) - selectObject(hov_obj); - } - } - emit glMouseReleaseEvent(e); -} - - -void QGLView::mousePressEvent(QMouseEvent * e) { -// qDebug() << "mousePressEvent" << e << isActive(); -// QGraphicsView::mousePressEvent(e); -// mouseThis_ = (scene()->itemAt(mapToScene(e->pos()) , QTransform() ) == 0); - selecting_ = false; - if (!QRect(QPoint(), size()).contains(e->pos())) return; - /// TODO select by rect - //if (e->button() == sel_button && e->modifiers() == sel_mod) - // selecting_ = true; - lastPos = e->pos(); - downPos = lastPos; - //qDebug() << mouseThis_; - emit glMousePressEvent(e); -} - - -void QGLView::mouseMoveEvent(QMouseEvent * e) { -// qDebug() << "mouseMoveEvent" << e << isActive(); -// QGraphicsView::mouseMoveEvent(e); - //lastPos = e->pos(); - if (selecting_) { - return; - } -// if (!QRect(QPoint(), size()).contains(e->pos())) return; - //if (scene()->itemAt(mapToScene(e->pos())) != 0) return; - ///qDebug() << e->x() << e->y(); - QRect g_rect(QPoint(), size()); - if (mouseRotate_) { - float dx = e->x() - lastPos.x(); - float dy = e->y() - lastPos.y(); - if (e->buttons() & Qt::LeftButton) { - //camera().angle_z += dx / 4.; - //camera().angle_xy += dy / 4.; - if (cameraOrbit_) { - camera()->orbitZ(dx / 4.f); - camera()->orbitXY(dy / 4.f); - } else { - camera()->rotateZ(dx / 4.f); - camera()->rotateXY(dy / 4.f); - } - emit cameraPosChanged(camera()->pos()); - } else if (e->buttons() & Qt::RightButton) { - float ad = camera()->distance(); - camera()->moveLeft(dx / 1000.f * ad); - camera()->moveUp(dy / 1000.f * ad); - //camera().pos.setX(camera().pos.x() + camera().pos.z() * dx / 500.); - //camera().pos.setY(camera().pos.y() - camera().pos.z() * dy / 500.); - emit cameraPosChanged(camera()->pos()); - } - //lights[0]->pos_ = camera().pos(); - } - if (customMouseMove_) emit customMouseMoveEvent(e->pos(), lastPos, e->buttons()); - lastPos = e->pos(); - if (grabMouse_) { - //if (!isrunning) return; - QCursor::setPos(mapToGlobal(QRect(QPoint(), size()).center())); - static bool mouse_sec = false; - if (mouse_sec) { - mouse_sec = false; - return; - } - if (mouse_first) { - mouse_first = false; - mouse_sec = true; - //qDebug() << "first" << e->pos(); - return; - } - lastPos = g_rect.center(); - int dx = e->x() - lastPos.x(); - int dy = e->y() - lastPos.y(); - emit glMouseMoveEvent(new QMouseEvent(QEvent::MouseMove, QPoint(dx, dy), e->button(), e->buttons(), e->modifiers())); - return; - } - emit glMouseMoveEvent(e); -} - - -void QGLView::wheelEvent(QWheelEvent * e) { - if (mouseRotate_) { - if (e->delta() > 0) camera()->flyCloser(0.1f); //camera().pos.setZ(camera().pos.z() - 0.1 * camera().pos.z()); - if (e->delta() < 0) camera()->flyFarer(0.1f); //camera().pos.setZ(camera().pos.z() + 0.1 * camera().pos.z()); - emit cameraPosChanged(camera()->pos()); - } - emit glWheelEvent(e); -} - - -void QGLView::leaveEvent(QEvent * ) { - lastPos = QPoint(-1, -1); - //qDebug() << lastPos; -} - - -void QGLView::keyPressEvent(QKeyEvent * e) { - emit glKeyPressEvent(e); - if (e->key() > 0) keys_.insert(e->key()); - if (e->key() == Qt::Key_F11) { - emit doubleClick(); - } -} - - -void QGLView::keyReleaseEvent(QKeyEvent * e) { - emit glKeyReleaseEvent(e); - keys_.remove(e->key()); -} - - -void QGLView::focusOutEvent(QFocusEvent *) { - keys_.clear(); -} - - -void QGLView::mouseDoubleClickEvent(QMouseEvent * e) { - if (e->buttons().testFlag(Qt::MidButton)) - emit doubleClick(); -} - - -QByteArray QGLView::saveCamera() { - ChunkStream cs; - const Camera * c = camera(); - cs.add(1, c->posX()); - cs.add(2, c->posY()); - cs.add(3, c->posZ()); - cs.add(4, c->aim().x()); - cs.add(5, c->aim().y()); - cs.add(6, c->aim().z()); - cs.add(7, c->angleZ()); - cs.add(8, c->angleXY()); - cs.add(9, c->angleRoll()); - cs.add(10, c->FOV()); - return cs.data(); -} - - -void QGLView::restoreCamera(const QByteArray &ba) { - if (ba.isEmpty()) return; - ChunkStream cs(ba); - QVector3D pos, aim, ang; - while (!cs.atEnd()) { - switch (cs.read()) { - case 1: pos.setX(cs.getData()); break; - case 2: pos.setY(cs.getData()); break; - case 3: pos.setZ(cs.getData()); break; - case 4: aim.setX(cs.getData()); break; - case 5: aim.setY(cs.getData()); break; - case 6: aim.setZ(cs.getData()); break; - case 7: ang.setZ(cs.getData()); break; - case 8: ang.setY(cs.getData()); break; - case 9: ang.setX(cs.getData()); break; - case 10: setFOV(cs.getData()); break; - default: break; - } - } - camera()->setPos(pos); - camera()->setAim(aim); - camera()->setAngles(ang); -} - - -QByteArray QGLView::saveFeatures() { - QByteArray ba; - QDataStream ds(&ba, QIODevice::WriteOnly); - ds << features_; - return ba; -} - - -void QGLView::restoreFeatures(const QByteArray & ba) { - QHash f; - QDataStream ds(ba); - ds >> f; - features_ = f; -} - +/* + QGLView + Ivan Pelipenko peri4ko@yandex.ru + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "qglview.h" + +#include +#include + + +QGLView::QGLView(): OpenGLWindow(), fbo_selection(3) { +// setFrameShape(QFrame::NoFrame); +// setViewportUpdateMode(FullViewportUpdate); +// setCacheMode(CacheNone); +// setMouseTracking(true); +// setFocusPolicy(Qt::WheelFocus); +// setScene(new QGraphicsScene()); +// setInteractive(true); + setIcon(QIcon("://icons/qglview.png")); + deleting_ = false; + timer = 0; + need_init_ = is_first_draw = true; + objects_.is_root = true; + objects_.view_ = this; + backColor_ = Qt::darkGray; + hoverHaloColor_ = QColor(195, 140, 255, 96); + selectionHaloColor_ = QColor(175, 255, 140); + ambientColor_ = QColor(10, 10, 10); + lastPos = QPoint(-1, -1); + lineWidth_ = 1.; + max_anisotropic = 1; + max_texture_chanels = 8; + cameraOrbit_ = lightEnabled_ = true; + shaders_supported = selecting_ = customMouseMove_ = false; + sel_button = Qt::LeftButton; + sel_mod = Qt::NoModifier; + renderer_ = nullptr; + fps_cnt = 0; + fps_tm = fps_ = 0.; + sel_obj = hov_obj = nullptr; + fogDensity_ = fogEnd_ = 1.; + fogStart_ = 0.; + fogMode_ = Exp; + hoverHaloFill_ = 0.333f; + selectionHaloFill_ = 0.5f; + //lmode = Simple; + shader_select = shader_halo = nullptr; + setFeature(qglMSAA, false); + setFeature(qglFXAA, false); + setFeature(qglLinearFiltering, true); + setFeature(qglAnisotropicLevel, 8); + setFeature(qglHDR, false); + setFeature(qglEyeAccomodationEnabled, false); + setFeature(qglEyeAccomodationTime, 16.); + setFeature(qglEyeAccomodationMaxSpeed, 0.2); + setFeature(qglBloomEnabled, false); + setFeature(qglBloomThreshold, 0.9); + setFeature(qglBloomFactor, 1.); + setFeature(qglBloomRadius, 8); + setFeature(qglMotionBlurEnabled, false); + setFeature(qglMotionBlurFactor, 1.); + setFeature(qglMotionBlurSteps, 8); + setFeature(qglShadowsEnabled, false); + setFeature(qglShadowsMapSize, 512); + setFeature(qglShadowsSoftEnabled, true); + setFeature(qglReflectionsEnabled, false); + setFeature(qglReflectionsBlur, true); + setFeature(qglSSAOEnabled, false); + setFeature(qglSSAORadius, 5); + setFeature(qglDepthOfFieldEnabled, false); + setFeature(qglDepthOfFieldAutoFocusEnabled, true); + setFeature(qglDepthOfFieldAutoFocusSpeed, 0.1); + setFeature(qglDepthOfFieldFocus, 1.); + setFeature(qglDepthOfFieldDiaphragm, 8.); + mouse_first = mouseSelect_ = hoverHalo_ = selectionHalo_ = true; + mouseRotate_ = true; + fogEnabled_ = is_init = grabMouse_ = shaders_bind = changed_ = false; + rmode = GLObjectBase::Fill; + sel_mode = QGLView::SingleSelection; +// sel_pen = QPen(Qt::black, 1, Qt::DashLine); +// sel_brush = QBrush(QColor(170, 100, 255, 120)); + camera()->setAim(QVector3D()); + camera()->setPos(QVector3D(2, 2, 2)); + camera()->setName("Camera"); + addObject(camera()); + emit cameraPosChanged(camera()->pos()); + //camera().aim_ = camera().pos_; + ktm_.restart(); +} + + +QGLView::~QGLView() { + stop(); + if (shader_select) delete shader_select; + if (shader_halo) delete shader_halo; + deleting_ = true; +} + + +void QGLView::stop() { + if (timer) killTimer(timer); + timer = 0; +} + + +void QGLView::start(float freq) { + stop(); + timer = startTimer(freq <= 0.f ? 0 : int(1000.f / freq)); +} + + +GLRendererBase * QGLView::renderer() { + return renderer_; +} + + +void QGLView::setRenderer(GLRendererBase * r, GLRendererBase ** prev) { + if (prev != nullptr) *prev = renderer_; + renderer_ = r; +} + + +void QGLView::addObject(GLObjectBase * o) { + objects_.addChild(o); + o->setView(this); + collectLights(); + QList cl = o->children(true); + cl << o; + foreach (GLObjectBase * i, cl) { + emit objectAdded(i); + } + if (is_init) { + o->init(); + } +} + + +int QGLView::objectsCount(bool all) { + if (!all) return objects_.childCount(); + int cnt = 0; + objectsCountInternal(&cnt, &objects_); + return cnt; +} + + +void QGLView::removeObject(GLObjectBase * o, bool inChildren) { + o->setView(nullptr); + if (inChildren) + removeObjectInternal(o, &objects_); + else + objects_.removeChild(o); + objectDeleted(o); +} + + +void QGLView::removeObject(GLObjectBase & o, bool inChildren) { + removeObject(&o, inChildren); +} + + +void QGLView::clearObjects(bool deleteAll) { + removeObject(camera_); + objects_.clearChildren(deleteAll); + addObject(camera()); + selectObject(nullptr); + hov_obj = nullptr; +} + + +QList QGLView::objects(bool all) { + return objects_.children(all); +} + + +int QGLView::lightsCount() const { + return lights_.size(); +} + + +void QGLView::removeLight(int index) { + removeObject(lights_.at(index)); + lights_.removeAt(index); +} + + +void QGLView::removeLight(Light * l) { + foreach (Light * i, lights_) + if (i == l) removeObject(i); + lights_.removeAll(l); +} + + +void QGLView::clearLights(bool deleteAll) { + if (deleteAll) + foreach (Light * i, lights_) delete i; + lights_.clear(); +} + + +void QGLView::addTexture(const QString & path) { + textures_manager->addTexture(path); +} + + +void QGLView::addAnimation(const QString & dir, const QString & name) { + textures_manager->addAnimation(dir, name); +} + + +Light * QGLView::light(int index) { + return lights_[index]; +} + + +Light * QGLView::light(const QString & name) { + foreach (Light * i, lights_) + if (i->name_ == name) return i; + return nullptr; +} + + +void QGLView::selectObject(GLObjectBase * o) { + if (o == sel_obj) return; + GLObjectBase * pso = sel_obj; + sel_obj = o; + emit selectionChanged(sel_obj, pso); +} + + +void QGLView::resizeEvent(QResizeEvent * e) { + renderLater(); +} + +void QGLView::timerEvent(QTimerEvent *) { + renderNow(); + if (ktm_.elapsed() < QApplication::keyboardInputInterval()) return; + Qt::KeyboardModifiers km = QApplication::keyboardModifiers(); + foreach (int i, keys_) + emit keyEvent((Qt::Key)i, km); +} + + +void QGLView::render() { + if (!isVisible()) return; + resizeGL(width(), height()); + QRect g_rect(QPoint(), size()); + emit glBeforePaint(); + //qDebug() << "paintGL"; + //QMutexLocker ml_v(&v_mutex); + glEnable(GL_CULL_FACE); + //glDisable(GL_CULL_FACE); + camera()->apply(aspect); + //objects_.preparePos(camera()); + start_rp.cam_offset_matrix = camera()->offsetMatrix(); + start_rp.proj_matrix = getGLMatrix(GL_PROJECTION_MATRIX); + start_rp.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX); + //objects_.buildTransform(); + + /// Selection detect + //glClearFramebuffer(QColor(100, 0, 0, 0)); + if (mouseSelect_) { + glReleaseTextures(); + glEnableDepth(); + glDisable(GL_TEXTURE_1D); + glDisable(GL_TEXTURE_2D); + glDisable(GL_TEXTURE_CUBE_MAP); + glDisable(GL_MULTISAMPLE); + glDisable(GL_LIGHTING); + glDisable(GL_BLEND); + glDisable(GL_ALPHA_TEST); + glDisable(GL_RESCALE_NORMAL); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + fbo_selection.bind(); + fbo_selection.setWriteBuffer(0); + glClearFramebuffer(QColor(0, 0, 0, 0)); + if (shaders_supported && shader_select->isLinked()) shader_select->bind(); + renderSelection(); + if (shaders_supported && shader_select->isLinked()) shader_select->release(); + uchar cgid[4] = {0, 0, 0, 0}; + uint iid = 0; + GLObjectBase * so = nullptr; + if (!g_rect.contains(lastPos)) { + if (hov_obj != nullptr) { + hov_obj = nullptr; + emit hoverChanged(nullptr, hov_obj); + } + } else { + glReadPixels(lastPos.x(), height() - lastPos.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, cgid); + iid = uint(cgid[0] << 24) | uint(cgid[1] << 16) | uint(cgid[2] << 8) | cgid[3]; + so = ids.value(iid, nullptr); + //qDebug() <name() << cgid[3]; + } + if (selectionHalo_ && sel_obj) { + fbo_selection.setWriteBuffer(2); + renderHalo(sel_obj, qHash((quint64)sel_obj), selectionHaloColor_, selectionHaloFill_); + } + if (hoverHalo_ && hov_obj) { + fbo_selection.setWriteBuffer(1); + renderHalo(hov_obj, iid, hoverHaloColor_, hoverHaloFill_); + } + fbo_selection.release(); + glEnableDepth(); + /*glEnableClientState(GL_NORMAL_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_COLOR_ARRAY);*/ + } + + camera()->apply(aspect); + start_rp.cam_offset_matrix = camera()->offsetMatrix(); + cur_mvpm = start_rp.proj_matrix * start_rp.view_matrix * start_rp.cam_offset_matrix; + //objects_.preparePos(camera()); + + static GLRendererBase * prev_rend = nullptr; + glShadeModel(GL_SMOOTH); + if (prev_rend != renderer_) { + prev_rend = renderer_; + if (renderer_ != nullptr) { + renderer_->init(width(), height()); + renderer_->resize(width(), height()); + renderer_->reloadShaders(); + } + } + emit glBeginPaint(); + if (renderer_ != nullptr) { + renderer_->rp.prepare(); + renderer_->prepareScene(); + renderer_->renderScene(); + } + emit glPainting(); + glUseProgram(0); + if (selectionHalo_ || hoverHalo_) { + glReleaseTextures(); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + + //glClearFramebuffer(Qt::black, false); + + glActiveTexture(GL_TEXTURE0); + glEnable(GL_BLEND); + glDisable(GL_TEXTURE_CUBE_MAP); + glDisable(GL_LIGHTING); + glDisableDepth(); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + if (selectionHalo_ && sel_obj) { + glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture(2)); + //qDebug() << "draw sel"; + glDrawQuad(); + } + if (hoverHalo_ && hov_obj) { + glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture(1)); + //qDebug() << "draw hover"; + //glBindTexture(GL_TEXTURE_2D, textures_manager->loadTexture("batt_pn.jpg")); + glDrawQuad(); + } + } + + glResetAllTransforms(); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glUseProgram(0); + + //glDisable(GL_BLEND); + //glDisable(GL_LIGHTING); + //glActiveTexture(GL_TEXTURE0); + //glBindTexture(GL_TEXTURE_2D, textures_manager->loadTexture("batt_pn.jpg")); + //glDrawQuad(); + + emit glEndPaint(); + + /*releaseShaders(); + glActiveTextureChannel(0); + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_LIGHTING); + glDisable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(0.3, 0.5, 0.8, 0.5); + glResetAllTransforms(); + glBegin(GL_QUADS); + glTexCoord2f(0.f, 0.f); glVertex2f(-1.f, -1.f); + glTexCoord2f(1.f, 0.f); glVertex2f(1.f, -1.); + glTexCoord2f(1.f, 1.f); glVertex2f(1.f, 1.f); + glTexCoord2f(0.f, 1.f); glVertex2f(-1.f, 1.f); + glEnd();*/ + /* + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glDisable(GL_LIGHTING); + glActiveTextureChannel(0); + glBindTexture(GL_TEXTURE_2D, fbo->texture()); + glDisable(GL_DEPTH_TEST); + glBegin(GL_QUADS); + glColor3f(1.f, 1.f, 1.f); + glTexCoord2f(0.f, 0.f); glVertex2f(-1.f, -1.f); + glTexCoord2f(0.f, 1.f); glVertex2f(-1.f, 1.f); + glTexCoord2f(1.f, 1.f); glVertex2f(1.f, 1.f); + glTexCoord2f(1.f, 0.f); glVertex2f(1.f, -1.); + glEnd(); + glEnable(GL_DEPTH_TEST);*/ + fps_tm += time.elapsed(); + time.restart(); + fps_cnt++; + if (fps_tm < 1000.) return; + fps_ = fps_cnt / fps_tm * 1000.; + fps_tm = 0.; + fps_cnt = 0; +} + + +void QGLView::initialize() { + //initializeOpenGLFunctions(); + glEnable(GL_TEXTURE_MAX_ANISOTROPY_EXT); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glEnableDepth(); + glEnable(GL_CULL_FACE); + glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); + glActiveTexture(GL_TEXTURE0 + 3); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + glEnable(GL_TEXTURE_GEN_R); + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); + glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); + glActiveTexture(GL_TEXTURE0); + glShadeModel(GL_SMOOTH); + glCullFace(GL_BACK); + glEnable(GL_COLOR_MATERIAL); + glColorMaterial(GL_FRONT, GL_DIFFUSE); + + textures_manager->loadTextures(); + objects_.initInternal(); + checkCaps(); + + shader_select = new QOpenGLShaderProgram(context()); + shader_halo = new QOpenGLShaderProgram(context()); + reloadThisShaders(); + is_init = true; + //resizeGL(width(), height()); + need_init_ = false; + emit glInitializeDone(); +} + + +void QGLView::renderHalo(const GLObjectBase * obj, const uint iid, const QColor & color, const float & fill) { + if (!shaders_supported) return; + if (!shader_halo) return; + if (!shader_halo->isLinked()) return; + if (obj) { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture()); + shader_halo->bind(); + shader_halo->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4()); + shader_halo->setUniformValue("t0", 0); + shader_halo->setUniformValue("dt", QVector2D(1.f / width(), 1.f / height())); + shader_halo->setUniformValue("selected", QVector4D(float((iid >> 24) & 0xFF) / 255.f, + float((iid >> 16) & 0xFF) / 255.f, + float((iid >> 8) & 0xFF) / 255.f, + float( iid & 0xFF) / 255.f)); + shader_halo->setUniformValue("color", color); + shader_halo->setUniformValue("fill", GLfloat(fill)); + //qDebug() << "render halo" << iid << shader_halo->log() << shader_halo->programId(); + glDisableDepth(); + //glClearFramebuffer(color); + glDrawQuad(shader_halo); + glDepthMask(GL_TRUE); + //glFlush(); + shader_halo->release(); + } else { + glClearFramebuffer(Qt::black, false); + } +} + + +void QGLView::renderSelection() { +// cid = 1; + ids.clear(); + if (shaders_supported) { + if (shader_select) { + if (shader_select->isLinked()) { + sh_id_loc = shader_select->uniformLocation("id"); + shader_select->setUniformValue("z_far", GLfloat(depthEnd())); + shader_select->setUniformValue("z_near", GLfloat(depthStart())); + } + } + } + //qDebug() << sh_id_loc; + start_rp.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX); + glPushMatrix(); + renderSingleSelection(objects_); + glPopMatrix(); +} + + +void QGLView::renderSingleSelection(GLObjectBase & o) { + if (!o.isInit()) { + o.init(); + o.loadTextures(); + } + if (!o.visible_ || !o.select_) return; + QMatrix4x4 curview = start_rp.view_matrix * start_rp.cam_offset_matrix * o.itransform_; + uint id = qHash((quint64)&o); + ids.insert(id, &o); + glLineWidth(o.line_width > 0.f ? o.line_width : lineWidth_); + glPointSize(o.line_width > 0.f ? o.line_width : lineWidth_); + if (shaders_supported){ + if (shader_select) { + if (shader_select->isLinked()) { + setUniformMatrices(shader_select, start_rp.proj_matrix, curview); + shader_select->setUniformValue(sh_id_loc, QVector4D(float((id >> 24) & 0xFF) / 255.f, + float((id >> 16) & 0xFF) / 255.f, + float((id >> 8) & 0xFF) / 255.f, + float(id & 0xFF) / 255.f)); + } + } + } else { + setGLMatrix(curview); + glColor4f(float((id >> 24) & 0xFF) / 255.f, + float((id >> 16) & 0xFF) / 255.f, + float((id >> 8) & 0xFF) / 255.f, + float(id & 0xFF) / 255.f); + } + //qDebug() << o.name() << "assign to" << sh_id_loc << cid; + //glColor4f(float((cid >> 24) & 0xFF) / 255.f, float((cid >> 16) & 0xFF) / 255.f, float((cid >> 8) & 0xFF) / 255.f, float(cid & 0xFF) / 255.f); +// ++cid; + o.draw(nullptr, true); + foreach (GLObjectBase * i, o.children_) + renderSingleSelection(*i); +} + + +void QGLView::collectLights() { + lights_.clear(); + collectObjectLights(&objects_); +} + + +void QGLView::objectDeleted(GLObjectBase * o) { + if (deleting_) return; + //qDebug() << "del" << o; + if (sel_obj == o) selectObject(nullptr); + if (hov_obj == o) hov_obj = nullptr; + collectLights(); +} + + +void QGLView::collectObjectLights(GLObjectBase * o) { + if (o->type_ == GLObjectBase::glLight) { + lights_ << globject_cast(o); + o->view_ = this; + } + foreach (GLObjectBase * i, o->children()) + collectObjectLights(i); +} + + +void QGLView::objectsCountInternal(int * cnt, GLObjectBase * where) { + ++(*cnt); + foreach (GLObjectBase * i, where->children_) + objectsCountInternal(cnt, i); +} + + +void QGLView::removeObjectInternal(GLObjectBase * o, GLObjectBase * where) { + foreach (GLObjectBase * i, where->children_) { + if (o == i) + where->removeChild(i); + else + removeObjectInternal(o, i); + objectDeleted(i); + } +} + + +void QGLView::checkCaps() { + glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropic); + //glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_chanels); + //qDebug() << max_texture_chanels; + //qDebug() << max_texture_chanels; + shaders_supported = QOpenGLShaderProgram::hasOpenGLShaderPrograms(); +} + + +void QGLView::reloadThisShaders() { + if (!shaders_supported) return; + loadShaders(shader_select, "selection", "://shaders"); + loadShaders(shader_halo, "selection_halo", "://shaders"); + //loadShaders(shader_rope, "rope", "://shaders"); +} + +void QGLView::glReleaseTextures(int channels) { + for (int i = channels - 1; i >= 0; --i) { + glActiveTexture(GL_TEXTURE0 + i); + glBindTexture(GL_TEXTURE_2D, 0); + glBindTexture(GL_TEXTURE_CUBE_MAP, 0); + } +} + + +void QGLView::applyFog() { + GLfloat fog_col[4] = {float(fogColor_.redF()), float(fogColor_.greenF()), float(fogColor_.blueF()), .0f}; + if (fogEnabled_) { + glEnable(GL_FOG); + glFogf(GL_FOG_DENSITY, fogDensity_); + glFogf(GL_FOG_START, fogStart_); + glFogf(GL_FOG_END, fogEnd_); + glFogi(GL_FOG_MODE, fogMode_); + fog_col[0] = fogColor_.redF(); + fog_col[1] = fogColor_.greenF(); + fog_col[2] = fogColor_.blueF(); + glFogfv(GL_FOG_COLOR, fog_col); + } else glDisable(GL_FOG); +} + + +void QGLView::resizeGL(int width, int height) { + if (!is_init) return; + if (width <= 0 || height <= 0) return; + if (prev_size == QSize(width, height)) return; + prev_size = QSize(width, height); + aspect = float(width) / float(height); + if (renderer_) renderer_->resize(width, height); + mouse_first = true; + //qDebug() << "resize" << width << height; + fbo_selection.resize(width, height); + iaspect = (aspect == 0.f) ? 0. : 1 / aspect; + glViewport(0, 0, width, height); + emit glResize(width, height); +} + + +void QGLView::mouseReleaseEvent(QMouseEvent * e) { +// qDebug() << "mouseReleaseEvent" << e << isActive(); +// QGraphicsView::mouseReleaseEvent(e); + //setCursor(QCursor(Qt::ArrowCursor)); + selecting_ = false; + if (mouseSelect_ && e->button() == Qt::LeftButton) { + if ((lastPos - downPos).manhattanLength() < 8) { + if (sel_obj != hov_obj) + selectObject(hov_obj); + } + } + emit glMouseReleaseEvent(e); +} + + +void QGLView::mousePressEvent(QMouseEvent * e) { +// qDebug() << "mousePressEvent" << e << isActive(); +// QGraphicsView::mousePressEvent(e); +// mouseThis_ = (scene()->itemAt(mapToScene(e->pos()) , QTransform() ) == 0); + selecting_ = false; + if (!QRect(QPoint(), size()).contains(e->pos())) return; + /// TODO select by rect + //if (e->button() == sel_button && e->modifiers() == sel_mod) + // selecting_ = true; + lastPos = e->pos(); + downPos = lastPos; + //qDebug() << mouseThis_; + emit glMousePressEvent(e); +} + + +void QGLView::mouseMoveEvent(QMouseEvent * e) { +// qDebug() << "mouseMoveEvent" << e << isActive(); +// QGraphicsView::mouseMoveEvent(e); + //lastPos = e->pos(); + if (selecting_) { + return; + } +// if (!QRect(QPoint(), size()).contains(e->pos())) return; + //if (scene()->itemAt(mapToScene(e->pos())) != 0) return; + ///qDebug() << e->x() << e->y(); + QRect g_rect(QPoint(), size()); + if (mouseRotate_) { + float dx = e->x() - lastPos.x(); + float dy = e->y() - lastPos.y(); + if (e->buttons() & Qt::LeftButton) { + //camera().angle_z += dx / 4.; + //camera().angle_xy += dy / 4.; + if (cameraOrbit_) { + camera()->orbitZ(dx / 4.f); + camera()->orbitXY(dy / 4.f); + } else { + camera()->rotateZ(dx / 4.f); + camera()->rotateXY(dy / 4.f); + } + emit cameraPosChanged(camera()->pos()); + } else if (e->buttons() & Qt::RightButton) { + float ad = camera()->distance(); + camera()->moveLeft(dx / 1000.f * ad); + camera()->moveUp(dy / 1000.f * ad); + //camera().pos.setX(camera().pos.x() + camera().pos.z() * dx / 500.); + //camera().pos.setY(camera().pos.y() - camera().pos.z() * dy / 500.); + emit cameraPosChanged(camera()->pos()); + } + //lights[0]->pos_ = camera().pos(); + } + if (customMouseMove_) emit customMouseMoveEvent(e->pos(), lastPos, e->buttons()); + lastPos = e->pos(); + if (grabMouse_) { + //if (!isrunning) return; + QCursor::setPos(mapToGlobal(QRect(QPoint(), size()).center())); + static bool mouse_sec = false; + if (mouse_sec) { + mouse_sec = false; + return; + } + if (mouse_first) { + mouse_first = false; + mouse_sec = true; + //qDebug() << "first" << e->pos(); + return; + } + lastPos = g_rect.center(); + int dx = e->x() - lastPos.x(); + int dy = e->y() - lastPos.y(); + emit glMouseMoveEvent(new QMouseEvent(QEvent::MouseMove, QPoint(dx, dy), e->button(), e->buttons(), e->modifiers())); + return; + } + emit glMouseMoveEvent(e); +} + + +void QGLView::wheelEvent(QWheelEvent * e) { + if (mouseRotate_) { + if (e->delta() > 0) camera()->flyCloser(0.1f); //camera().pos.setZ(camera().pos.z() - 0.1 * camera().pos.z()); + if (e->delta() < 0) camera()->flyFarer(0.1f); //camera().pos.setZ(camera().pos.z() + 0.1 * camera().pos.z()); + emit cameraPosChanged(camera()->pos()); + } + emit glWheelEvent(e); +} + + +void QGLView::leaveEvent(QEvent * ) { + lastPos = QPoint(-1, -1); + //qDebug() << lastPos; +} + + +void QGLView::keyPressEvent(QKeyEvent * e) { + emit glKeyPressEvent(e); + if (e->key() > 0) keys_.insert(e->key()); + if (e->key() == Qt::Key_F11) { + emit doubleClick(); + } +} + + +void QGLView::keyReleaseEvent(QKeyEvent * e) { + emit glKeyReleaseEvent(e); + keys_.remove(e->key()); +} + + +void QGLView::focusOutEvent(QFocusEvent *) { + keys_.clear(); +} + + +void QGLView::mouseDoubleClickEvent(QMouseEvent * e) { + if (e->buttons().testFlag(Qt::MidButton)) + emit doubleClick(); +} + + +QByteArray QGLView::saveCamera() { + ChunkStream cs; + const Camera * c = camera(); + cs.add(1, c->posX()); + cs.add(2, c->posY()); + cs.add(3, c->posZ()); + cs.add(4, c->aim().x()); + cs.add(5, c->aim().y()); + cs.add(6, c->aim().z()); + cs.add(7, c->angleZ()); + cs.add(8, c->angleXY()); + cs.add(9, c->angleRoll()); + cs.add(10, c->FOV()); + return cs.data(); +} + + +void QGLView::restoreCamera(const QByteArray &ba) { + if (ba.isEmpty()) return; + ChunkStream cs(ba); + QVector3D pos, aim, ang; + while (!cs.atEnd()) { + switch (cs.read()) { + case 1: pos.setX(cs.getData()); break; + case 2: pos.setY(cs.getData()); break; + case 3: pos.setZ(cs.getData()); break; + case 4: aim.setX(cs.getData()); break; + case 5: aim.setY(cs.getData()); break; + case 6: aim.setZ(cs.getData()); break; + case 7: ang.setZ(cs.getData()); break; + case 8: ang.setY(cs.getData()); break; + case 9: ang.setX(cs.getData()); break; + case 10: setFOV(cs.getData()); break; + default: break; + } + } + camera()->setPos(pos); + camera()->setAim(aim); + camera()->setAngles(ang); +} + + +QByteArray QGLView::saveFeatures() { + QByteArray ba; + QDataStream ds(&ba, QIODevice::WriteOnly); + ds << features_; + return ba; +} + + +void QGLView::restoreFeatures(const QByteArray & ba) { + QHash f; + QDataStream ds(ba); + ds >> f; + features_ = f; +} + diff --git a/qglview/qglview.h b/libs/qglview/qglview.h similarity index 97% rename from qglview/qglview.h rename to libs/qglview/qglview.h index c9ac9fb..dcb1d0e 100644 --- a/qglview/qglview.h +++ b/libs/qglview/qglview.h @@ -1,301 +1,301 @@ -/* - QGLView - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef QGLVIEW_H -#define QGLVIEW_H - -#include "openglwindow.h" -#include "glframebuffer.h" -#include "glprimitives.h" -#include "glparticles_system.h" -#include "glrendererbase.h" -#include - - -class QGLView: public OpenGLWindow, public QGLViewBase -{ - friend class GLRendererBase; - friend class GLObjectBase; - Q_OBJECT - Q_PROPERTY (QColor backColor READ backColor WRITE setBackColor) - Q_PROPERTY (float lineWidth READ lineWidth WRITE setLineWidth) - Q_PROPERTY (float FOV READ FOV WRITE setFOV) - Q_PROPERTY (float depthStart READ depthStart WRITE setDepthStart) - Q_PROPERTY (float depthEnd READ depthEnd WRITE setDepthEnd) - Q_PROPERTY (QColor ambientColor READ ambientColor WRITE setAmbientColor) - Q_PROPERTY (QColor fogColor READ fogColor WRITE setFogColor) - Q_PROPERTY (float fogDensity READ fogDensity WRITE setFogDensity) - Q_PROPERTY (float fogStart READ fogStart WRITE setFogStart) - Q_PROPERTY (float fogEnd READ fogEnd WRITE setFogEnd) - Q_PROPERTY (FogMode fogMode READ fogMode WRITE setFogMode) - Q_PROPERTY (bool fogEnabled READ isFogEnabled WRITE setFogEnabled) - Q_PROPERTY (int renderMode READ renderMode WRITE setRenderMode) - Q_PROPERTY (bool grabMouse READ isGrabMouseEnabled WRITE setGrabMouseEnabled) - Q_PROPERTY (bool mouseRotate READ isMouseRotateEnabled WRITE setMouseRotateEnabled) - Q_PROPERTY (bool mouseSelection READ isMouseSelectionEnabled WRITE setMouseSelectionEnabled) - Q_PROPERTY (bool cameraOrbit READ isCameraOrbit WRITE setCameraOrbit) - Q_PROPERTY (bool hoverHalo READ isHoverHaloEnabled WRITE setHoverHaloEnabled) - Q_PROPERTY (QColor hoverHaloColor READ hoverHaloColor WRITE setHoverHaloColor) - Q_PROPERTY (float hoverHaloFillAlpha READ hoverHaloFillAlpha WRITE setHoverHaloFillAlpha) - Q_PROPERTY (bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled) - Q_PROPERTY (QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor) - Q_PROPERTY (float selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha) - Q_PROPERTY (Qt::MouseButton selectionButton READ selectionButton WRITE setSelectionButton) - Q_PROPERTY (Qt::KeyboardModifier selectionModifier READ selectionModifier WRITE setSelectionModifier) - Q_PROPERTY (SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) - -public: - QGLView(); - virtual ~QGLView(); - - enum FogMode {Linear = GL_LINEAR, Exp = GL_EXP, Exp2 = GL_EXP2}; - enum SelectionMode {NoSelection, SingleSelection, MultiSelection}; - enum Feature { - qglMSAA, - qglFXAA, - qglLinearFiltering, - qglAnisotropicLevel, - qglHDR, - qglEyeAccomodationEnabled, - qglEyeAccomodationTime, - qglEyeAccomodationMaxSpeed, - qglBloomEnabled, - qglBloomThreshold, - qglBloomFactor, - qglBloomRadius, - qglMotionBlurEnabled, - qglMotionBlurFactor, - qglMotionBlurSteps, - qglShadowsEnabled, - qglShadowsMapSize, - qglShadowsSoftEnabled, - qglReflectionsEnabled, - qglReflectionsBlur, - qglSSAOEnabled, - qglSSAORadius, - qglDepthOfFieldEnabled, - qglDepthOfFieldAutoFocusEnabled, - qglDepthOfFieldAutoFocusSpeed, - qglDepthOfFieldFocus, - qglDepthOfFieldDiaphragm - }; - - Q_ENUMS (FogMode) - Q_ENUMS (SelectionMode) - - void stop(); - void start(float freq = 60.); - - GLRendererBase * renderer(); - void setRenderer(GLRendererBase * r, GLRendererBase ** prev = nullptr); - - QColor backColor() const {return backColor_;} - float lineWidth() const {return lineWidth_;} - float FOV() const {return camera()->fov_;} - float depthStart() const {return camera()->depth_start;} - float depthEnd() const {return camera()->depth_end;} - float currentFPS() const {return fps_;} - int maxAnisotropicLevel() const {return max_anisotropic;} - - QColor ambientColor() const {return ambientColor_;} - QColor fogColor() const {return fogColor_;} - float fogDensity() const {return fogDensity_;} - float fogStart() const {return fogStart_;} - float fogEnd() const {return fogEnd_;} - FogMode fogMode() const {return fogMode_;} - bool isFogEnabled() const {return fogEnabled_;} - bool isLightEnabled() const {return lightEnabled_;} - bool isGrabMouseEnabled() const {return grabMouse_;} - bool isMouseRotateEnabled() const {return mouseRotate_;} - bool isMouseSelectionEnabled() const {return mouseSelect_;} - bool isCameraOrbit() const {return cameraOrbit_;} - bool isHoverHaloEnabled() const {return hoverHalo_;} - QColor hoverHaloColor() const {return hoverHaloColor_;} - float hoverHaloFillAlpha() const {return hoverHaloFill_;} - bool isSelectionHaloEnabled() const {return selectionHalo_;} - QColor selectionHaloColor() const {return selectionHaloColor_;} - float selectionHaloFillAlpha() const {return selectionHaloFill_;} - - QVariant feature(Feature f) const {return features_.value(int(f));} - QVariant setFeature(Feature f, const QVariant & value) {QVariant ret = features_.value(int(f)); features_[int(f)] = value; return ret;} - bool isFeatureEnabled(Feature f) const {return features_[int(f)].toBool();} - - int renderMode() const {return (int)rmode;} - void setRenderMode(int mode) {rmode = (GLObjectBase::RenderMode)mode;} - - void addObject(GLObjectBase * o); -// void addObject(GLObjectBase & o) {addObject(&o);} - int objectsCount(bool all = false); - void removeObject(GLObjectBase * o, bool inChildren = true); - void removeObject(GLObjectBase & o, bool inChildren = true); - void clearObjects(bool deleteAll = false); - QList objects(bool all = false); - - int lightsCount() const; - void removeLight(int index); - void removeLight(Light * l); - void clearLights(bool deleteAll = false); - QList lights() {return lights_;} - - void addTexture(const QString & path); - void addAnimation(const QString & dir, const QString & name); - - const GLObjectBase & rootObject() {return objects_;} - GLObjectBase * object(int index) {return objects_.child(index);} - GLObjectBase * object(const QString & name) {return objects_.child(name);} - Light * light(int index); - Light * light(const QString & name); - - SelectionMode selectionMode() const {return sel_mode;} - Qt::MouseButton selectionButton() const {return sel_button;} - Qt::KeyboardModifier selectionModifier() const {return sel_mod;} - - void setSelectionMode(SelectionMode v) {sel_mode = v;} - void setSelectionButton(Qt::MouseButton v) {sel_button = v;} - void setSelectionModifier(Qt::KeyboardModifier v) {sel_mod = v;} - void selectObject(GLObjectBase * o); - GLObjectBase * selectedObject() const {return sel_obj;} - - void glReleaseTextures(int channels = 8); - QByteArray saveCamera(); - void restoreCamera(const QByteArray & ba); - QByteArray saveFeatures(); - void restoreFeatures(const QByteArray & ba); - - - GLfloat aspect, iaspect; - QMatrix4x4 cur_mvpm; - -protected: - void render(); - void resizeEvent(QResizeEvent * e); - - void timerEvent(QTimerEvent * ); - void initialize(); - void resizeGL(int width, int height); - void mousePressEvent(QMouseEvent * e); - void mouseMoveEvent(QMouseEvent * e); - void mouseReleaseEvent(QMouseEvent * e); - void wheelEvent(QWheelEvent * e); - void leaveEvent(QEvent * ); - void mouseDoubleClickEvent(QMouseEvent * e); - - void keyPressEvent(QKeyEvent * e); - void keyReleaseEvent(QKeyEvent * e); - void focusOutEvent(QFocusEvent *); - - void applyFog(); - void renderSelection(); - - void checkCaps(); - void collectLights(); - -private: - void objectDeleted(GLObjectBase * o); - void collectObjectLights(GLObjectBase * o); - void objectsCountInternal(int * cnt, GLObjectBase * where); - void removeObjectInternal(GLObjectBase * o, GLObjectBase * where); - void renderSingleSelection(GLObjectBase & o); - //void renderSingleShadow(GLObjectBase & o); - void renderHalo(const GLObjectBase * obj, const uint iid, const QColor & color, const float & fill); - void reloadThisShaders(); - void processKeys(); - bool setupViewport(); - - QPoint lastPos, downPos; - GLObjectBase objects_; - QList lights_; -// uint cid; - QHash ids; - QSet keys_; - FogMode fogMode_; - QColor backColor_, fogColor_, ambientColor_, hoverHaloColor_, selectionHaloColor_; - QTime time, ktm_; - GLint max_anisotropic, max_texture_chanels; - GLObjectBase::RenderMode rmode; - GLObjectBase * sel_obj, * hov_obj; - GLFramebuffer fbo_selection; - QOpenGLShaderProgram * shader_select, * shader_halo; - GLRendererBase * renderer_; - SelectionMode sel_mode; - Qt::MouseButton sel_button; - Qt::KeyboardModifier sel_mod; - GLRendererBase::RenderingParameters start_rp; - QHash features_; - QSize prev_size; - float lineWidth_; - float fogDensity_, fogStart_, fogEnd_, fps_, fps_tm, hoverHaloFill_, selectionHaloFill_, m_motionBlurFactor; - int timer, fps_cnt, sh_id_loc, deleting_; - bool is_first_draw, is_init, fogEnabled_, lightEnabled_, grabMouse_, mouse_first, mouseRotate_, mouseSelect_, customMouseMove_; - bool shaders_supported, changed_, cameraOrbit_, need_init_; - bool hoverHalo_, selectionHalo_, shaders_bind, selecting_; - -public slots: - void setBackColor(const QColor & arg) {backColor_ = arg;} - void setLineWidth(const float & arg) {lineWidth_ = arg;} - void setFOV(const float & arg) {camera()->fov_ = arg;} - void setDepthStart(const float & arg) {camera()->depth_start = arg;} - void setDepthEnd(const float & arg) {camera()->depth_end = arg;} - void setAmbientColor(const QColor & arg) {ambientColor_ = arg;} - void setFogColor(const QColor & arg) {fogColor_ = arg;} - void setFogDensity(const float & arg) {fogDensity_ = arg;} - void setFogStart(const float & arg) {fogStart_ = arg;} - void setFogEnd(const float & arg) {fogEnd_ = arg;} - void setFogMode(const FogMode & arg) {fogMode_ = arg;} - void setFogEnabled(const bool & arg) {fogEnabled_ = arg;} - void setLightEnabled(const bool & arg) {lightEnabled_ = arg;} - void setGrabMouseEnabled(const bool & arg) {grabMouse_ = arg; mouse_first = true;} - void setMouseRotateEnabled(const bool & arg) {mouseRotate_ = arg;} - void setMouseSelectionEnabled(const bool & arg) {mouseSelect_ = arg;} - void setCustomMouseMove(const bool & arg) {customMouseMove_ = arg;} - void setCameraOrbit(const bool & arg) {cameraOrbit_ = arg;} - void setHoverHaloEnabled(const bool & arg) {hoverHalo_ = arg;} - void setHoverHaloColor(const QColor & arg) {hoverHaloColor_ = arg;} - void setHoverHaloFillAlpha(const float & arg) {hoverHaloFill_ = arg;} - void setSelectionHaloEnabled(const bool & arg) {selectionHalo_ = arg;} - void setSelectionHaloColor(const QColor & arg) {selectionHaloColor_ = arg;} - void setSelectionHaloFillAlpha(const float & arg) {selectionHaloFill_ = arg;} - - void reloadShaders() {if (renderer_ != nullptr) renderer_->reloadShaders(); reloadThisShaders();} - void deselect() {sel_obj = nullptr;} - -signals: - void glBeforePaint(); - void glBeginPaint(); - void glPainting(); - void glEndPaint(); - void glKeyPressEvent(QKeyEvent * e); - void glKeyReleaseEvent(QKeyEvent * e); - void glMousePressEvent(QMouseEvent * e); - void glMouseMoveEvent(QMouseEvent * e); - void glMouseReleaseEvent(QMouseEvent * e); - void glWheelEvent(QWheelEvent * e); - void glResize(int, int); - void glInitializeDone(); - void cameraPosChanged(QVector3D pos); - void keyEvent(Qt::Key key, Qt::KeyboardModifiers mod); - void customMouseMoveEvent(QPoint curpos, QPoint lastpos, Qt::MouseButtons buttons); - - void hoverChanged(GLObjectBase * cur, GLObjectBase * prev); - void selectionChanged(GLObjectBase * cur, GLObjectBase * prev); - void objectAdded(GLObjectBase * ); - void doubleClick(); - -}; - -#endif // QGLVIEW_H +/* + QGLView + Ivan Pelipenko peri4ko@yandex.ru + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#ifndef QGLVIEW_H +#define QGLVIEW_H + +#include "openglwindow.h" +#include "glframebuffer.h" +#include "glprimitives.h" +#include "glparticles_system.h" +#include "glrendererbase.h" +#include + + +class QGLView: public OpenGLWindow, public QGLViewBase +{ + friend class GLRendererBase; + friend class GLObjectBase; + Q_OBJECT + Q_PROPERTY (QColor backColor READ backColor WRITE setBackColor) + Q_PROPERTY (float lineWidth READ lineWidth WRITE setLineWidth) + Q_PROPERTY (float FOV READ FOV WRITE setFOV) + Q_PROPERTY (float depthStart READ depthStart WRITE setDepthStart) + Q_PROPERTY (float depthEnd READ depthEnd WRITE setDepthEnd) + Q_PROPERTY (QColor ambientColor READ ambientColor WRITE setAmbientColor) + Q_PROPERTY (QColor fogColor READ fogColor WRITE setFogColor) + Q_PROPERTY (float fogDensity READ fogDensity WRITE setFogDensity) + Q_PROPERTY (float fogStart READ fogStart WRITE setFogStart) + Q_PROPERTY (float fogEnd READ fogEnd WRITE setFogEnd) + Q_PROPERTY (FogMode fogMode READ fogMode WRITE setFogMode) + Q_PROPERTY (bool fogEnabled READ isFogEnabled WRITE setFogEnabled) + Q_PROPERTY (int renderMode READ renderMode WRITE setRenderMode) + Q_PROPERTY (bool grabMouse READ isGrabMouseEnabled WRITE setGrabMouseEnabled) + Q_PROPERTY (bool mouseRotate READ isMouseRotateEnabled WRITE setMouseRotateEnabled) + Q_PROPERTY (bool mouseSelection READ isMouseSelectionEnabled WRITE setMouseSelectionEnabled) + Q_PROPERTY (bool cameraOrbit READ isCameraOrbit WRITE setCameraOrbit) + Q_PROPERTY (bool hoverHalo READ isHoverHaloEnabled WRITE setHoverHaloEnabled) + Q_PROPERTY (QColor hoverHaloColor READ hoverHaloColor WRITE setHoverHaloColor) + Q_PROPERTY (float hoverHaloFillAlpha READ hoverHaloFillAlpha WRITE setHoverHaloFillAlpha) + Q_PROPERTY (bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled) + Q_PROPERTY (QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor) + Q_PROPERTY (float selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha) + Q_PROPERTY (Qt::MouseButton selectionButton READ selectionButton WRITE setSelectionButton) + Q_PROPERTY (Qt::KeyboardModifier selectionModifier READ selectionModifier WRITE setSelectionModifier) + Q_PROPERTY (SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) + +public: + QGLView(); + virtual ~QGLView(); + + enum FogMode {Linear = GL_LINEAR, Exp = GL_EXP, Exp2 = GL_EXP2}; + enum SelectionMode {NoSelection, SingleSelection, MultiSelection}; + enum Feature { + qglMSAA, + qglFXAA, + qglLinearFiltering, + qglAnisotropicLevel, + qglHDR, + qglEyeAccomodationEnabled, + qglEyeAccomodationTime, + qglEyeAccomodationMaxSpeed, + qglBloomEnabled, + qglBloomThreshold, + qglBloomFactor, + qglBloomRadius, + qglMotionBlurEnabled, + qglMotionBlurFactor, + qglMotionBlurSteps, + qglShadowsEnabled, + qglShadowsMapSize, + qglShadowsSoftEnabled, + qglReflectionsEnabled, + qglReflectionsBlur, + qglSSAOEnabled, + qglSSAORadius, + qglDepthOfFieldEnabled, + qglDepthOfFieldAutoFocusEnabled, + qglDepthOfFieldAutoFocusSpeed, + qglDepthOfFieldFocus, + qglDepthOfFieldDiaphragm + }; + + Q_ENUMS (FogMode) + Q_ENUMS (SelectionMode) + + void stop(); + void start(float freq = 60.); + + GLRendererBase * renderer(); + void setRenderer(GLRendererBase * r, GLRendererBase ** prev = nullptr); + + QColor backColor() const {return backColor_;} + float lineWidth() const {return lineWidth_;} + float FOV() const {return camera()->fov_;} + float depthStart() const {return camera()->depth_start;} + float depthEnd() const {return camera()->depth_end;} + float currentFPS() const {return fps_;} + int maxAnisotropicLevel() const {return max_anisotropic;} + + QColor ambientColor() const {return ambientColor_;} + QColor fogColor() const {return fogColor_;} + float fogDensity() const {return fogDensity_;} + float fogStart() const {return fogStart_;} + float fogEnd() const {return fogEnd_;} + FogMode fogMode() const {return fogMode_;} + bool isFogEnabled() const {return fogEnabled_;} + bool isLightEnabled() const {return lightEnabled_;} + bool isGrabMouseEnabled() const {return grabMouse_;} + bool isMouseRotateEnabled() const {return mouseRotate_;} + bool isMouseSelectionEnabled() const {return mouseSelect_;} + bool isCameraOrbit() const {return cameraOrbit_;} + bool isHoverHaloEnabled() const {return hoverHalo_;} + QColor hoverHaloColor() const {return hoverHaloColor_;} + float hoverHaloFillAlpha() const {return hoverHaloFill_;} + bool isSelectionHaloEnabled() const {return selectionHalo_;} + QColor selectionHaloColor() const {return selectionHaloColor_;} + float selectionHaloFillAlpha() const {return selectionHaloFill_;} + + QVariant feature(Feature f) const {return features_.value(int(f));} + QVariant setFeature(Feature f, const QVariant & value) {QVariant ret = features_.value(int(f)); features_[int(f)] = value; return ret;} + bool isFeatureEnabled(Feature f) const {return features_[int(f)].toBool();} + + int renderMode() const {return (int)rmode;} + void setRenderMode(int mode) {rmode = (GLObjectBase::RenderMode)mode;} + + void addObject(GLObjectBase * o); +// void addObject(GLObjectBase & o) {addObject(&o);} + int objectsCount(bool all = false); + void removeObject(GLObjectBase * o, bool inChildren = true); + void removeObject(GLObjectBase & o, bool inChildren = true); + void clearObjects(bool deleteAll = false); + QList objects(bool all = false); + + int lightsCount() const; + void removeLight(int index); + void removeLight(Light * l); + void clearLights(bool deleteAll = false); + QList lights() {return lights_;} + + void addTexture(const QString & path); + void addAnimation(const QString & dir, const QString & name); + + const GLObjectBase & rootObject() {return objects_;} + GLObjectBase * object(int index) {return objects_.child(index);} + GLObjectBase * object(const QString & name) {return objects_.child(name);} + Light * light(int index); + Light * light(const QString & name); + + SelectionMode selectionMode() const {return sel_mode;} + Qt::MouseButton selectionButton() const {return sel_button;} + Qt::KeyboardModifier selectionModifier() const {return sel_mod;} + + void setSelectionMode(SelectionMode v) {sel_mode = v;} + void setSelectionButton(Qt::MouseButton v) {sel_button = v;} + void setSelectionModifier(Qt::KeyboardModifier v) {sel_mod = v;} + void selectObject(GLObjectBase * o); + GLObjectBase * selectedObject() const {return sel_obj;} + + void glReleaseTextures(int channels = 8); + QByteArray saveCamera(); + void restoreCamera(const QByteArray & ba); + QByteArray saveFeatures(); + void restoreFeatures(const QByteArray & ba); + + + GLfloat aspect, iaspect; + QMatrix4x4 cur_mvpm; + +protected: + void render(); + void resizeEvent(QResizeEvent * e); + + void timerEvent(QTimerEvent * ); + void initialize(); + void resizeGL(int width, int height); + void mousePressEvent(QMouseEvent * e); + void mouseMoveEvent(QMouseEvent * e); + void mouseReleaseEvent(QMouseEvent * e); + void wheelEvent(QWheelEvent * e); + void leaveEvent(QEvent * ); + void mouseDoubleClickEvent(QMouseEvent * e); + + void keyPressEvent(QKeyEvent * e); + void keyReleaseEvent(QKeyEvent * e); + void focusOutEvent(QFocusEvent *); + + void applyFog(); + void renderSelection(); + + void checkCaps(); + void collectLights(); + +private: + void objectDeleted(GLObjectBase * o); + void collectObjectLights(GLObjectBase * o); + void objectsCountInternal(int * cnt, GLObjectBase * where); + void removeObjectInternal(GLObjectBase * o, GLObjectBase * where); + void renderSingleSelection(GLObjectBase & o); + //void renderSingleShadow(GLObjectBase & o); + void renderHalo(const GLObjectBase * obj, const uint iid, const QColor & color, const float & fill); + void reloadThisShaders(); + void processKeys(); + bool setupViewport(); + + QPoint lastPos, downPos; + GLObjectBase objects_; + QList lights_; +// uint cid; + QHash ids; + QSet keys_; + FogMode fogMode_; + QColor backColor_, fogColor_, ambientColor_, hoverHaloColor_, selectionHaloColor_; + QTime time, ktm_; + GLint max_anisotropic, max_texture_chanels; + GLObjectBase::RenderMode rmode; + GLObjectBase * sel_obj, * hov_obj; + GLFramebuffer fbo_selection; + QOpenGLShaderProgram * shader_select, * shader_halo; + GLRendererBase * renderer_; + SelectionMode sel_mode; + Qt::MouseButton sel_button; + Qt::KeyboardModifier sel_mod; + GLRendererBase::RenderingParameters start_rp; + QHash features_; + QSize prev_size; + float lineWidth_; + float fogDensity_, fogStart_, fogEnd_, fps_, fps_tm, hoverHaloFill_, selectionHaloFill_, m_motionBlurFactor; + int timer, fps_cnt, sh_id_loc, deleting_; + bool is_first_draw, is_init, fogEnabled_, lightEnabled_, grabMouse_, mouse_first, mouseRotate_, mouseSelect_, customMouseMove_; + bool shaders_supported, changed_, cameraOrbit_, need_init_; + bool hoverHalo_, selectionHalo_, shaders_bind, selecting_; + +public slots: + void setBackColor(const QColor & arg) {backColor_ = arg;} + void setLineWidth(const float & arg) {lineWidth_ = arg;} + void setFOV(const float & arg) {camera()->fov_ = arg;} + void setDepthStart(const float & arg) {camera()->depth_start = arg;} + void setDepthEnd(const float & arg) {camera()->depth_end = arg;} + void setAmbientColor(const QColor & arg) {ambientColor_ = arg;} + void setFogColor(const QColor & arg) {fogColor_ = arg;} + void setFogDensity(const float & arg) {fogDensity_ = arg;} + void setFogStart(const float & arg) {fogStart_ = arg;} + void setFogEnd(const float & arg) {fogEnd_ = arg;} + void setFogMode(const FogMode & arg) {fogMode_ = arg;} + void setFogEnabled(const bool & arg) {fogEnabled_ = arg;} + void setLightEnabled(const bool & arg) {lightEnabled_ = arg;} + void setGrabMouseEnabled(const bool & arg) {grabMouse_ = arg; mouse_first = true;} + void setMouseRotateEnabled(const bool & arg) {mouseRotate_ = arg;} + void setMouseSelectionEnabled(const bool & arg) {mouseSelect_ = arg;} + void setCustomMouseMove(const bool & arg) {customMouseMove_ = arg;} + void setCameraOrbit(const bool & arg) {cameraOrbit_ = arg;} + void setHoverHaloEnabled(const bool & arg) {hoverHalo_ = arg;} + void setHoverHaloColor(const QColor & arg) {hoverHaloColor_ = arg;} + void setHoverHaloFillAlpha(const float & arg) {hoverHaloFill_ = arg;} + void setSelectionHaloEnabled(const bool & arg) {selectionHalo_ = arg;} + void setSelectionHaloColor(const QColor & arg) {selectionHaloColor_ = arg;} + void setSelectionHaloFillAlpha(const float & arg) {selectionHaloFill_ = arg;} + + void reloadShaders() {if (renderer_ != nullptr) renderer_->reloadShaders(); reloadThisShaders();} + void deselect() {sel_obj = nullptr;} + +signals: + void glBeforePaint(); + void glBeginPaint(); + void glPainting(); + void glEndPaint(); + void glKeyPressEvent(QKeyEvent * e); + void glKeyReleaseEvent(QKeyEvent * e); + void glMousePressEvent(QMouseEvent * e); + void glMouseMoveEvent(QMouseEvent * e); + void glMouseReleaseEvent(QMouseEvent * e); + void glWheelEvent(QWheelEvent * e); + void glResize(int, int); + void glInitializeDone(); + void cameraPosChanged(QVector3D pos); + void keyEvent(Qt::Key key, Qt::KeyboardModifiers mod); + void customMouseMoveEvent(QPoint curpos, QPoint lastpos, Qt::MouseButtons buttons); + + void hoverChanged(GLObjectBase * cur, GLObjectBase * prev); + void selectionChanged(GLObjectBase * cur, GLObjectBase * prev); + void objectAdded(GLObjectBase * ); + void doubleClick(); + +}; + +#endif // QGLVIEW_H diff --git a/qglview/qglview.qrc b/libs/qglview/qglview.qrc similarity index 100% rename from qglview/qglview.qrc rename to libs/qglview/qglview.qrc diff --git a/qglview/qglview_test/main.cpp b/libs/qglview/qglview_test/main.cpp similarity index 100% rename from qglview/qglview_test/main.cpp rename to libs/qglview/qglview_test/main.cpp diff --git a/qglview/qglview_test/qglview_window.cpp b/libs/qglview/qglview_test/qglview_window.cpp similarity index 100% rename from qglview/qglview_test/qglview_window.cpp rename to libs/qglview/qglview_test/qglview_window.cpp diff --git a/qglview/qglview_test/qglview_window.h b/libs/qglview/qglview_test/qglview_window.h similarity index 100% rename from qglview/qglview_test/qglview_window.h rename to libs/qglview/qglview_test/qglview_window.h diff --git a/qglview/qglview_test/qglview_window.ui b/libs/qglview/qglview_test/qglview_window.ui similarity index 100% rename from qglview/qglview_test/qglview_window.ui rename to libs/qglview/qglview_test/qglview_window.ui diff --git a/qglview/renderer_deferred_shading.cpp b/libs/qglview/renderer_deferred_shading.cpp similarity index 100% rename from qglview/renderer_deferred_shading.cpp rename to libs/qglview/renderer_deferred_shading.cpp diff --git a/qglview/renderer_deferred_shading.h b/libs/qglview/renderer_deferred_shading.h similarity index 100% rename from qglview/renderer_deferred_shading.h rename to libs/qglview/renderer_deferred_shading.h diff --git a/qglview/renderer_simple.cpp b/libs/qglview/renderer_simple.cpp similarity index 100% rename from qglview/renderer_simple.cpp rename to libs/qglview/renderer_simple.cpp diff --git a/qglview/renderer_simple.h b/libs/qglview/renderer_simple.h similarity index 100% rename from qglview/renderer_simple.h rename to libs/qglview/renderer_simple.h diff --git a/qglview/shaders/FXAA.frag b/libs/qglview/shaders/FXAA.frag similarity index 100% rename from qglview/shaders/FXAA.frag rename to libs/qglview/shaders/FXAA.frag diff --git a/qglview/shaders/FXAA.vert b/libs/qglview/shaders/FXAA.vert similarity index 100% rename from qglview/shaders/FXAA.vert rename to libs/qglview/shaders/FXAA.vert diff --git a/qglview/shaders/bloom_0.frag b/libs/qglview/shaders/bloom_0.frag similarity index 100% rename from qglview/shaders/bloom_0.frag rename to libs/qglview/shaders/bloom_0.frag diff --git a/qglview/shaders/bloom_1.frag b/libs/qglview/shaders/bloom_1.frag similarity index 100% rename from qglview/shaders/bloom_1.frag rename to libs/qglview/shaders/bloom_1.frag diff --git a/qglview/shaders/bloom_pass_0.frag b/libs/qglview/shaders/bloom_pass_0.frag similarity index 100% rename from qglview/shaders/bloom_pass_0.frag rename to libs/qglview/shaders/bloom_pass_0.frag diff --git a/qglview/shaders/bloom_pass_0.vert b/libs/qglview/shaders/bloom_pass_0.vert similarity index 100% rename from qglview/shaders/bloom_pass_0.vert rename to libs/qglview/shaders/bloom_pass_0.vert diff --git a/qglview/shaders/bloom_pass_1.frag b/libs/qglview/shaders/bloom_pass_1.frag similarity index 100% rename from qglview/shaders/bloom_pass_1.frag rename to libs/qglview/shaders/bloom_pass_1.frag diff --git a/qglview/shaders/bloom_pass_1.vert b/libs/qglview/shaders/bloom_pass_1.vert similarity index 100% rename from qglview/shaders/bloom_pass_1.vert rename to libs/qglview/shaders/bloom_pass_1.vert diff --git a/qglview/shaders/dof.frag b/libs/qglview/shaders/dof.frag similarity index 100% rename from qglview/shaders/dof.frag rename to libs/qglview/shaders/dof.frag diff --git a/qglview/shaders/dof.vert b/libs/qglview/shaders/dof.vert similarity index 100% rename from qglview/shaders/dof.vert rename to libs/qglview/shaders/dof.vert diff --git a/qglview/shaders/downscale.frag b/libs/qglview/shaders/downscale.frag similarity index 100% rename from qglview/shaders/downscale.frag rename to libs/qglview/shaders/downscale.frag diff --git a/qglview/shaders/downscale.vert b/libs/qglview/shaders/downscale.vert similarity index 100% rename from qglview/shaders/downscale.vert rename to libs/qglview/shaders/downscale.vert diff --git a/qglview/shaders/dsl_pass_0.frag b/libs/qglview/shaders/dsl_pass_0.frag similarity index 100% rename from qglview/shaders/dsl_pass_0.frag rename to libs/qglview/shaders/dsl_pass_0.frag diff --git a/qglview/shaders/dsl_pass_0.vert b/libs/qglview/shaders/dsl_pass_0.vert similarity index 100% rename from qglview/shaders/dsl_pass_0.vert rename to libs/qglview/shaders/dsl_pass_0.vert diff --git a/qglview/shaders/dsl_pass_1.frag b/libs/qglview/shaders/dsl_pass_1.frag similarity index 100% rename from qglview/shaders/dsl_pass_1.frag rename to libs/qglview/shaders/dsl_pass_1.frag diff --git a/qglview/shaders/dsl_pass_1.vert b/libs/qglview/shaders/dsl_pass_1.vert similarity index 100% rename from qglview/shaders/dsl_pass_1.vert rename to libs/qglview/shaders/dsl_pass_1.vert diff --git a/qglview/shaders/dsl_pass_2.frag b/libs/qglview/shaders/dsl_pass_2.frag similarity index 100% rename from qglview/shaders/dsl_pass_2.frag rename to libs/qglview/shaders/dsl_pass_2.frag diff --git a/qglview/shaders/dsl_pass_2.vert b/libs/qglview/shaders/dsl_pass_2.vert similarity index 100% rename from qglview/shaders/dsl_pass_2.vert rename to libs/qglview/shaders/dsl_pass_2.vert diff --git a/qglview/shaders/fbo_add.frag b/libs/qglview/shaders/fbo_add.frag similarity index 100% rename from qglview/shaders/fbo_add.frag rename to libs/qglview/shaders/fbo_add.frag diff --git a/qglview/shaders/fbo_add.vert b/libs/qglview/shaders/fbo_add.vert similarity index 100% rename from qglview/shaders/fbo_add.vert rename to libs/qglview/shaders/fbo_add.vert diff --git a/qglengine/shaders/fxaa_v3.h b/libs/qglview/shaders/fxaa_v3.h similarity index 100% rename from qglengine/shaders/fxaa_v3.h rename to libs/qglview/shaders/fxaa_v3.h diff --git a/qglview/shaders/hdr.frag b/libs/qglview/shaders/hdr.frag similarity index 100% rename from qglview/shaders/hdr.frag rename to libs/qglview/shaders/hdr.frag diff --git a/qglview/shaders/hdr.vert b/libs/qglview/shaders/hdr.vert similarity index 100% rename from qglview/shaders/hdr.vert rename to libs/qglview/shaders/hdr.vert diff --git a/qglview/shaders/hdr_scale_0.frag b/libs/qglview/shaders/hdr_scale_0.frag similarity index 100% rename from qglview/shaders/hdr_scale_0.frag rename to libs/qglview/shaders/hdr_scale_0.frag diff --git a/qglview/shaders/hdr_scale_1.frag b/libs/qglview/shaders/hdr_scale_1.frag similarity index 100% rename from qglview/shaders/hdr_scale_1.frag rename to libs/qglview/shaders/hdr_scale_1.frag diff --git a/qglview/shaders/light_models.frag b/libs/qglview/shaders/light_models.frag similarity index 100% rename from qglview/shaders/light_models.frag rename to libs/qglview/shaders/light_models.frag diff --git a/qglview/shaders/motion_blur.frag b/libs/qglview/shaders/motion_blur.frag similarity index 100% rename from qglview/shaders/motion_blur.frag rename to libs/qglview/shaders/motion_blur.frag diff --git a/qglview/shaders/motion_blur.vert b/libs/qglview/shaders/motion_blur.vert similarity index 100% rename from qglview/shaders/motion_blur.vert rename to libs/qglview/shaders/motion_blur.vert diff --git a/qglview/shaders/post.frag b/libs/qglview/shaders/post.frag similarity index 100% rename from qglview/shaders/post.frag rename to libs/qglview/shaders/post.frag diff --git a/qglview/shaders/ppl.frag b/libs/qglview/shaders/ppl.frag similarity index 100% rename from qglview/shaders/ppl.frag rename to libs/qglview/shaders/ppl.frag diff --git a/qglview/shaders/ppl.vert b/libs/qglview/shaders/ppl.vert similarity index 100% rename from qglview/shaders/ppl.vert rename to libs/qglview/shaders/ppl.vert diff --git a/qglview/shaders/selection.frag b/libs/qglview/shaders/selection.frag similarity index 100% rename from qglview/shaders/selection.frag rename to libs/qglview/shaders/selection.frag diff --git a/qglview/shaders/selection.vert b/libs/qglview/shaders/selection.vert similarity index 100% rename from qglview/shaders/selection.vert rename to libs/qglview/shaders/selection.vert diff --git a/qglview/shaders/selection_halo.frag b/libs/qglview/shaders/selection_halo.frag similarity index 100% rename from qglview/shaders/selection_halo.frag rename to libs/qglview/shaders/selection_halo.frag diff --git a/qglview/shaders/selection_halo.vert b/libs/qglview/shaders/selection_halo.vert similarity index 100% rename from qglview/shaders/selection_halo.vert rename to libs/qglview/shaders/selection_halo.vert diff --git a/qglview/shaders/shadow.frag b/libs/qglview/shaders/shadow.frag similarity index 100% rename from qglview/shaders/shadow.frag rename to libs/qglview/shaders/shadow.frag diff --git a/qglview/shaders/shadow.vert b/libs/qglview/shaders/shadow.vert similarity index 100% rename from qglview/shaders/shadow.vert rename to libs/qglview/shaders/shadow.vert diff --git a/qglview/shaders/ssao_blur.frag b/libs/qglview/shaders/ssao_blur.frag similarity index 100% rename from qglview/shaders/ssao_blur.frag rename to libs/qglview/shaders/ssao_blur.frag diff --git a/qglview/shaders/ssao_blur.vert b/libs/qglview/shaders/ssao_blur.vert similarity index 100% rename from qglview/shaders/ssao_blur.vert rename to libs/qglview/shaders/ssao_blur.vert diff --git a/qglview/shaders/ssao_merge.frag b/libs/qglview/shaders/ssao_merge.frag similarity index 100% rename from qglview/shaders/ssao_merge.frag rename to libs/qglview/shaders/ssao_merge.frag diff --git a/qglview/shaders/ssao_merge.vert b/libs/qglview/shaders/ssao_merge.vert similarity index 100% rename from qglview/shaders/ssao_merge.vert rename to libs/qglview/shaders/ssao_merge.vert diff --git a/qglview/shaders/ssr.frag b/libs/qglview/shaders/ssr.frag similarity index 100% rename from qglview/shaders/ssr.frag rename to libs/qglview/shaders/ssr.frag diff --git a/qglview/shaders/ssr.vert b/libs/qglview/shaders/ssr.vert similarity index 100% rename from qglview/shaders/ssr.vert rename to libs/qglview/shaders/ssr.vert diff --git a/qglview/shaders/ssr_blur.frag b/libs/qglview/shaders/ssr_blur.frag similarity index 100% rename from qglview/shaders/ssr_blur.frag rename to libs/qglview/shaders/ssr_blur.frag diff --git a/qglview/shaders/ssr_blur.vert b/libs/qglview/shaders/ssr_blur.vert similarity index 100% rename from qglview/shaders/ssr_blur.vert rename to libs/qglview/shaders/ssr_blur.vert diff --git a/qglview/shaders/ssr_merge.frag b/libs/qglview/shaders/ssr_merge.frag similarity index 100% rename from qglview/shaders/ssr_merge.frag rename to libs/qglview/shaders/ssr_merge.frag diff --git a/qglview/shaders/ssr_merge.vert b/libs/qglview/shaders/ssr_merge.vert similarity index 100% rename from qglview/shaders/ssr_merge.vert rename to libs/qglview/shaders/ssr_merge.vert diff --git a/qad/libs/sql_table/CMakeLists.txt b/libs/sql_table/CMakeLists.txt similarity index 100% rename from qad/libs/sql_table/CMakeLists.txt rename to libs/sql_table/CMakeLists.txt diff --git a/qad/libs/sql_table/lang/qad_sql_table_en.ts b/libs/sql_table/lang/qad_sql_table_en.ts similarity index 100% rename from qad/libs/sql_table/lang/qad_sql_table_en.ts rename to libs/sql_table/lang/qad_sql_table_en.ts diff --git a/qad/libs/sql_table/lang/qad_sql_table_ru.ts b/libs/sql_table/lang/qad_sql_table_ru.ts similarity index 100% rename from qad/libs/sql_table/lang/qad_sql_table_ru.ts rename to libs/sql_table/lang/qad_sql_table_ru.ts diff --git a/qad/libs/sql_table/lang/update.bat b/libs/sql_table/lang/update.bat similarity index 100% rename from qad/libs/sql_table/lang/update.bat rename to libs/sql_table/lang/update.bat diff --git a/qad/libs/sql_table/plugin/CMakeLists.txt b/libs/sql_table/plugin/CMakeLists.txt similarity index 100% rename from qad/libs/sql_table/plugin/CMakeLists.txt rename to libs/sql_table/plugin/CMakeLists.txt diff --git a/qad/libs/sql_table/plugin/qad_sql_table.cpp b/libs/sql_table/plugin/qad_sql_table.cpp similarity index 100% rename from qad/libs/sql_table/plugin/qad_sql_table.cpp rename to libs/sql_table/plugin/qad_sql_table.cpp diff --git a/qad/libs/sql_table/plugin/qad_sql_table.h b/libs/sql_table/plugin/qad_sql_table.h similarity index 100% rename from qad/libs/sql_table/plugin/qad_sql_table.h rename to libs/sql_table/plugin/qad_sql_table.h diff --git a/qad/libs/sql_table/plugin/sql_record_plugin.cpp b/libs/sql_table/plugin/sql_record_plugin.cpp similarity index 100% rename from qad/libs/sql_table/plugin/sql_record_plugin.cpp rename to libs/sql_table/plugin/sql_record_plugin.cpp diff --git a/qad/libs/sql_table/plugin/sql_record_plugin.h b/libs/sql_table/plugin/sql_record_plugin.h similarity index 100% rename from qad/libs/sql_table/plugin/sql_record_plugin.h rename to libs/sql_table/plugin/sql_record_plugin.h diff --git a/qad/libs/sql_table/plugin/sql_table_plugin.cpp b/libs/sql_table/plugin/sql_table_plugin.cpp similarity index 100% rename from qad/libs/sql_table/plugin/sql_table_plugin.cpp rename to libs/sql_table/plugin/sql_table_plugin.cpp diff --git a/qad/libs/sql_table/plugin/sql_table_plugin.h b/libs/sql_table/plugin/sql_table_plugin.h similarity index 100% rename from qad/libs/sql_table/plugin/sql_table_plugin.h rename to libs/sql_table/plugin/sql_table_plugin.h diff --git a/qad/libs/sql_table/qad_sql_table.qrc b/libs/sql_table/qad_sql_table.qrc similarity index 100% rename from qad/libs/sql_table/qad_sql_table.qrc rename to libs/sql_table/qad_sql_table.qrc diff --git a/qad/libs/sql_table/sql_record_widget.cpp b/libs/sql_table/sql_record_widget.cpp similarity index 100% rename from qad/libs/sql_table/sql_record_widget.cpp rename to libs/sql_table/sql_record_widget.cpp diff --git a/qad/libs/sql_table/sql_record_widget.h b/libs/sql_table/sql_record_widget.h similarity index 100% rename from qad/libs/sql_table/sql_record_widget.h rename to libs/sql_table/sql_record_widget.h diff --git a/qad/libs/sql_table/sql_table_widget.cpp b/libs/sql_table/sql_table_widget.cpp similarity index 100% rename from qad/libs/sql_table/sql_table_widget.cpp rename to libs/sql_table/sql_table_widget.cpp diff --git a/qad/libs/sql_table/sql_table_widget.h b/libs/sql_table/sql_table_widget.h similarity index 100% rename from qad/libs/sql_table/sql_table_widget.h rename to libs/sql_table/sql_table_widget.h diff --git a/qad/libs/sql_table/sql_table_widget.ui b/libs/sql_table/sql_table_widget.ui similarity index 100% rename from qad/libs/sql_table/sql_table_widget.ui rename to libs/sql_table/sql_table_widget.ui diff --git a/qad/libs/touch_widgets/CMakeLists.txt b/libs/touch_widgets/CMakeLists.txt similarity index 100% rename from qad/libs/touch_widgets/CMakeLists.txt rename to libs/touch_widgets/CMakeLists.txt diff --git a/qad/libs/touch_widgets/plugin/CMakeLists.txt b/libs/touch_widgets/plugin/CMakeLists.txt similarity index 100% rename from qad/libs/touch_widgets/plugin/CMakeLists.txt rename to libs/touch_widgets/plugin/CMakeLists.txt diff --git a/qad/libs/touch_widgets/plugin/qad_touch_widgets.cpp b/libs/touch_widgets/plugin/qad_touch_widgets.cpp similarity index 100% rename from qad/libs/touch_widgets/plugin/qad_touch_widgets.cpp rename to libs/touch_widgets/plugin/qad_touch_widgets.cpp diff --git a/qad/libs/touch_widgets/plugin/qad_touch_widgets.h b/libs/touch_widgets/plugin/qad_touch_widgets.h similarity index 100% rename from qad/libs/touch_widgets/plugin/qad_touch_widgets.h rename to libs/touch_widgets/plugin/qad_touch_widgets.h diff --git a/qad/libs/touch_widgets/plugin/touchbuttframeplugin.cpp b/libs/touch_widgets/plugin/touchbuttframeplugin.cpp similarity index 100% rename from qad/libs/touch_widgets/plugin/touchbuttframeplugin.cpp rename to libs/touch_widgets/plugin/touchbuttframeplugin.cpp diff --git a/qad/libs/touch_widgets/plugin/touchbuttframeplugin.h b/libs/touch_widgets/plugin/touchbuttframeplugin.h similarity index 100% rename from qad/libs/touch_widgets/plugin/touchbuttframeplugin.h rename to libs/touch_widgets/plugin/touchbuttframeplugin.h diff --git a/qad/libs/touch_widgets/plugin/touchbuttonplugin.cpp b/libs/touch_widgets/plugin/touchbuttonplugin.cpp similarity index 100% rename from qad/libs/touch_widgets/plugin/touchbuttonplugin.cpp rename to libs/touch_widgets/plugin/touchbuttonplugin.cpp diff --git a/qad/libs/touch_widgets/plugin/touchbuttonplugin.h b/libs/touch_widgets/plugin/touchbuttonplugin.h similarity index 100% rename from qad/libs/touch_widgets/plugin/touchbuttonplugin.h rename to libs/touch_widgets/plugin/touchbuttonplugin.h diff --git a/qad/libs/touch_widgets/plugin/touchsliderplugin.cpp b/libs/touch_widgets/plugin/touchsliderplugin.cpp similarity index 100% rename from qad/libs/touch_widgets/plugin/touchsliderplugin.cpp rename to libs/touch_widgets/plugin/touchsliderplugin.cpp diff --git a/qad/libs/touch_widgets/plugin/touchsliderplugin.h b/libs/touch_widgets/plugin/touchsliderplugin.h similarity index 100% rename from qad/libs/touch_widgets/plugin/touchsliderplugin.h rename to libs/touch_widgets/plugin/touchsliderplugin.h diff --git a/qad/libs/touch_widgets/touch_bar.h b/libs/touch_widgets/touch_bar.h similarity index 100% rename from qad/libs/touch_widgets/touch_bar.h rename to libs/touch_widgets/touch_bar.h diff --git a/qad/libs/touch_widgets/touch_widgets.qrc b/libs/touch_widgets/touch_widgets.qrc similarity index 100% rename from qad/libs/touch_widgets/touch_widgets.qrc rename to libs/touch_widgets/touch_widgets.qrc diff --git a/qad/libs/touch_widgets/touchbuttframe.cpp b/libs/touch_widgets/touchbuttframe.cpp similarity index 100% rename from qad/libs/touch_widgets/touchbuttframe.cpp rename to libs/touch_widgets/touchbuttframe.cpp diff --git a/qad/libs/touch_widgets/touchbuttframe.h b/libs/touch_widgets/touchbuttframe.h similarity index 100% rename from qad/libs/touch_widgets/touchbuttframe.h rename to libs/touch_widgets/touchbuttframe.h diff --git a/qad/libs/touch_widgets/touchbutton.cpp b/libs/touch_widgets/touchbutton.cpp similarity index 100% rename from qad/libs/touch_widgets/touchbutton.cpp rename to libs/touch_widgets/touchbutton.cpp diff --git a/qad/libs/touch_widgets/touchbutton.h b/libs/touch_widgets/touchbutton.h similarity index 100% rename from qad/libs/touch_widgets/touchbutton.h rename to libs/touch_widgets/touchbutton.h diff --git a/qad/libs/touch_widgets/touchslider.cpp b/libs/touch_widgets/touchslider.cpp similarity index 100% rename from qad/libs/touch_widgets/touchslider.cpp rename to libs/touch_widgets/touchslider.cpp diff --git a/qad/libs/touch_widgets/touchslider.h b/libs/touch_widgets/touchslider.h similarity index 100% rename from qad/libs/touch_widgets/touchslider.h rename to libs/touch_widgets/touchslider.h diff --git a/qad/libs/touch_widgets/touchslider.ui b/libs/touch_widgets/touchslider.ui similarity index 100% rename from qad/libs/touch_widgets/touchslider.ui rename to libs/touch_widgets/touchslider.ui diff --git a/qad/libs/utils/CMakeLists.txt b/libs/utils/CMakeLists.txt similarity index 100% rename from qad/libs/utils/CMakeLists.txt rename to libs/utils/CMakeLists.txt diff --git a/qad/libs/utils/chunkstream.cpp b/libs/utils/chunkstream.cpp similarity index 100% rename from qad/libs/utils/chunkstream.cpp rename to libs/utils/chunkstream.cpp diff --git a/qad/libs/utils/chunkstream.h b/libs/utils/chunkstream.h similarity index 100% rename from qad/libs/utils/chunkstream.h rename to libs/utils/chunkstream.h diff --git a/qad/libs/utils/plugin/CMakeLists.txt b/libs/utils/plugin/CMakeLists.txt similarity index 100% rename from qad/libs/utils/plugin/CMakeLists.txt rename to libs/utils/plugin/CMakeLists.txt diff --git a/qad/libs/utils/plugin/qad_utils.cpp b/libs/utils/plugin/qad_utils.cpp similarity index 100% rename from qad/libs/utils/plugin/qad_utils.cpp rename to libs/utils/plugin/qad_utils.cpp diff --git a/qad/libs/utils/plugin/qad_utils.h b/libs/utils/plugin/qad_utils.h similarity index 100% rename from qad/libs/utils/plugin/qad_utils.h rename to libs/utils/plugin/qad_utils.h diff --git a/qad/libs/utils/propertystorage.cpp b/libs/utils/propertystorage.cpp similarity index 100% rename from qad/libs/utils/propertystorage.cpp rename to libs/utils/propertystorage.cpp diff --git a/qad/libs/utils/propertystorage.h b/libs/utils/propertystorage.h similarity index 100% rename from qad/libs/utils/propertystorage.h rename to libs/utils/propertystorage.h diff --git a/qad/libs/utils/qad_locations.cpp b/libs/utils/qad_locations.cpp similarity index 100% rename from qad/libs/utils/qad_locations.cpp rename to libs/utils/qad_locations.cpp diff --git a/qad/libs/utils/qad_locations.h b/libs/utils/qad_locations.h similarity index 100% rename from qad/libs/utils/qad_locations.h rename to libs/utils/qad_locations.h diff --git a/qad/libs/utils/qad_types.cpp b/libs/utils/qad_types.cpp similarity index 100% rename from qad/libs/utils/qad_types.cpp rename to libs/utils/qad_types.cpp diff --git a/qad/libs/utils/qad_types.h b/libs/utils/qad_types.h similarity index 100% rename from qad/libs/utils/qad_types.h rename to libs/utils/qad_types.h diff --git a/qad/libs/utils/qad_utils.qrc b/libs/utils/qad_utils.qrc similarity index 100% rename from qad/libs/utils/qad_utils.qrc rename to libs/utils/qad_utils.qrc diff --git a/qad/libs/utils/qpiconfig.cpp b/libs/utils/qpiconfig.cpp similarity index 100% rename from qad/libs/utils/qpiconfig.cpp rename to libs/utils/qpiconfig.cpp diff --git a/qad/libs/utils/qpiconfig.h b/libs/utils/qpiconfig.h similarity index 100% rename from qad/libs/utils/qpiconfig.h rename to libs/utils/qpiconfig.h diff --git a/qad/libs/utils/qpievaluator.cpp b/libs/utils/qpievaluator.cpp similarity index 100% rename from qad/libs/utils/qpievaluator.cpp rename to libs/utils/qpievaluator.cpp diff --git a/qad/libs/utils/qpievaluator.h b/libs/utils/qpievaluator.h similarity index 100% rename from qad/libs/utils/qpievaluator.h rename to libs/utils/qpievaluator.h diff --git a/qad/libs/widgets/CMakeLists.txt b/libs/widgets/CMakeLists.txt similarity index 100% rename from qad/libs/widgets/CMakeLists.txt rename to libs/widgets/CMakeLists.txt diff --git a/qad/libs/widgets/chardialog.cpp b/libs/widgets/chardialog.cpp similarity index 100% rename from qad/libs/widgets/chardialog.cpp rename to libs/widgets/chardialog.cpp diff --git a/qad/libs/widgets/chardialog.h b/libs/widgets/chardialog.h similarity index 100% rename from qad/libs/widgets/chardialog.h rename to libs/widgets/chardialog.h diff --git a/qad/libs/widgets/chardialog.ui b/libs/widgets/chardialog.ui similarity index 100% rename from qad/libs/widgets/chardialog.ui rename to libs/widgets/chardialog.ui diff --git a/qad/libs/widgets/clineedit.cpp b/libs/widgets/clineedit.cpp similarity index 100% rename from qad/libs/widgets/clineedit.cpp rename to libs/widgets/clineedit.cpp diff --git a/qad/libs/widgets/clineedit.h b/libs/widgets/clineedit.h similarity index 100% rename from qad/libs/widgets/clineedit.h rename to libs/widgets/clineedit.h diff --git a/qad/libs/widgets/colorbutton.cpp b/libs/widgets/colorbutton.cpp similarity index 100% rename from qad/libs/widgets/colorbutton.cpp rename to libs/widgets/colorbutton.cpp diff --git a/qad/libs/widgets/colorbutton.h b/libs/widgets/colorbutton.h similarity index 100% rename from qad/libs/widgets/colorbutton.h rename to libs/widgets/colorbutton.h diff --git a/qad/libs/widgets/ecombobox.cpp b/libs/widgets/ecombobox.cpp similarity index 100% rename from qad/libs/widgets/ecombobox.cpp rename to libs/widgets/ecombobox.cpp diff --git a/qad/libs/widgets/ecombobox.h b/libs/widgets/ecombobox.h similarity index 100% rename from qad/libs/widgets/ecombobox.h rename to libs/widgets/ecombobox.h diff --git a/qad/libs/widgets/evalspinbox.cpp b/libs/widgets/evalspinbox.cpp similarity index 100% rename from qad/libs/widgets/evalspinbox.cpp rename to libs/widgets/evalspinbox.cpp diff --git a/qad/libs/widgets/evalspinbox.h b/libs/widgets/evalspinbox.h similarity index 100% rename from qad/libs/widgets/evalspinbox.h rename to libs/widgets/evalspinbox.h diff --git a/qad/libs/widgets/iconedlabel.cpp b/libs/widgets/iconedlabel.cpp similarity index 100% rename from qad/libs/widgets/iconedlabel.cpp rename to libs/widgets/iconedlabel.cpp diff --git a/qad/libs/widgets/iconedlabel.h b/libs/widgets/iconedlabel.h similarity index 100% rename from qad/libs/widgets/iconedlabel.h rename to libs/widgets/iconedlabel.h diff --git a/qad/libs/widgets/image_view.cpp b/libs/widgets/image_view.cpp similarity index 100% rename from qad/libs/widgets/image_view.cpp rename to libs/widgets/image_view.cpp diff --git a/qad/libs/widgets/image_view.h b/libs/widgets/image_view.h similarity index 100% rename from qad/libs/widgets/image_view.h rename to libs/widgets/image_view.h diff --git a/qad/libs/widgets/lang/qad_widgets_en.ts b/libs/widgets/lang/qad_widgets_en.ts similarity index 100% rename from qad/libs/widgets/lang/qad_widgets_en.ts rename to libs/widgets/lang/qad_widgets_en.ts diff --git a/qad/libs/widgets/lang/qad_widgets_ru.ts b/libs/widgets/lang/qad_widgets_ru.ts similarity index 100% rename from qad/libs/widgets/lang/qad_widgets_ru.ts rename to libs/widgets/lang/qad_widgets_ru.ts diff --git a/qad/libs/widgets/lang/update.bat b/libs/widgets/lang/update.bat similarity index 100% rename from qad/libs/widgets/lang/update.bat rename to libs/widgets/lang/update.bat diff --git a/qad/libs/widgets/mathmatrixedit.cpp b/libs/widgets/mathmatrixedit.cpp similarity index 100% rename from qad/libs/widgets/mathmatrixedit.cpp rename to libs/widgets/mathmatrixedit.cpp diff --git a/qad/libs/widgets/mathmatrixedit.h b/libs/widgets/mathmatrixedit.h similarity index 100% rename from qad/libs/widgets/mathmatrixedit.h rename to libs/widgets/mathmatrixedit.h diff --git a/qad/libs/widgets/mathvectoredit.cpp b/libs/widgets/mathvectoredit.cpp similarity index 100% rename from qad/libs/widgets/mathvectoredit.cpp rename to libs/widgets/mathvectoredit.cpp diff --git a/qad/libs/widgets/mathvectoredit.h b/libs/widgets/mathvectoredit.h similarity index 100% rename from qad/libs/widgets/mathvectoredit.h rename to libs/widgets/mathvectoredit.h diff --git a/qad/libs/widgets/matrixedit.cpp b/libs/widgets/matrixedit.cpp similarity index 100% rename from qad/libs/widgets/matrixedit.cpp rename to libs/widgets/matrixedit.cpp diff --git a/qad/libs/widgets/matrixedit.h b/libs/widgets/matrixedit.h similarity index 100% rename from qad/libs/widgets/matrixedit.h rename to libs/widgets/matrixedit.h diff --git a/qad/libs/widgets/matrixedit.ui b/libs/widgets/matrixedit.ui similarity index 100% rename from qad/libs/widgets/matrixedit.ui rename to libs/widgets/matrixedit.ui diff --git a/qad/libs/widgets/plugin/CMakeLists.txt b/libs/widgets/plugin/CMakeLists.txt similarity index 100% rename from qad/libs/widgets/plugin/CMakeLists.txt rename to libs/widgets/plugin/CMakeLists.txt diff --git a/qad/libs/widgets/plugin/chardialogplugin.cpp b/libs/widgets/plugin/chardialogplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/chardialogplugin.cpp rename to libs/widgets/plugin/chardialogplugin.cpp diff --git a/qad/libs/widgets/plugin/chardialogplugin.h b/libs/widgets/plugin/chardialogplugin.h similarity index 100% rename from qad/libs/widgets/plugin/chardialogplugin.h rename to libs/widgets/plugin/chardialogplugin.h diff --git a/qad/libs/widgets/plugin/clineeditplugin.cpp b/libs/widgets/plugin/clineeditplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/clineeditplugin.cpp rename to libs/widgets/plugin/clineeditplugin.cpp diff --git a/qad/libs/widgets/plugin/clineeditplugin.h b/libs/widgets/plugin/clineeditplugin.h similarity index 100% rename from qad/libs/widgets/plugin/clineeditplugin.h rename to libs/widgets/plugin/clineeditplugin.h diff --git a/qad/libs/widgets/plugin/colorbuttonplugin.cpp b/libs/widgets/plugin/colorbuttonplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/colorbuttonplugin.cpp rename to libs/widgets/plugin/colorbuttonplugin.cpp diff --git a/qad/libs/widgets/plugin/colorbuttonplugin.h b/libs/widgets/plugin/colorbuttonplugin.h similarity index 100% rename from qad/libs/widgets/plugin/colorbuttonplugin.h rename to libs/widgets/plugin/colorbuttonplugin.h diff --git a/qad/libs/widgets/plugin/ecomboboxplugin.cpp b/libs/widgets/plugin/ecomboboxplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/ecomboboxplugin.cpp rename to libs/widgets/plugin/ecomboboxplugin.cpp diff --git a/qad/libs/widgets/plugin/ecomboboxplugin.h b/libs/widgets/plugin/ecomboboxplugin.h similarity index 100% rename from qad/libs/widgets/plugin/ecomboboxplugin.h rename to libs/widgets/plugin/ecomboboxplugin.h diff --git a/qad/libs/widgets/plugin/evalspinboxplugin.cpp b/libs/widgets/plugin/evalspinboxplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/evalspinboxplugin.cpp rename to libs/widgets/plugin/evalspinboxplugin.cpp diff --git a/qad/libs/widgets/plugin/evalspinboxplugin.h b/libs/widgets/plugin/evalspinboxplugin.h similarity index 100% rename from qad/libs/widgets/plugin/evalspinboxplugin.h rename to libs/widgets/plugin/evalspinboxplugin.h diff --git a/qad/libs/widgets/plugin/iconedlabelplugin.h b/libs/widgets/plugin/iconedlabelplugin.h similarity index 100% rename from qad/libs/widgets/plugin/iconedlabelplugin.h rename to libs/widgets/plugin/iconedlabelplugin.h diff --git a/qad/libs/widgets/plugin/imageviewplugin.cpp b/libs/widgets/plugin/imageviewplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/imageviewplugin.cpp rename to libs/widgets/plugin/imageviewplugin.cpp diff --git a/qad/libs/widgets/plugin/imageviewplugin.h b/libs/widgets/plugin/imageviewplugin.h similarity index 100% rename from qad/libs/widgets/plugin/imageviewplugin.h rename to libs/widgets/plugin/imageviewplugin.h diff --git a/qad/libs/widgets/plugin/lconedlabelplugin.cpp b/libs/widgets/plugin/lconedlabelplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/lconedlabelplugin.cpp rename to libs/widgets/plugin/lconedlabelplugin.cpp diff --git a/qad/libs/widgets/plugin/qad_widgets.cpp b/libs/widgets/plugin/qad_widgets.cpp similarity index 100% rename from qad/libs/widgets/plugin/qad_widgets.cpp rename to libs/widgets/plugin/qad_widgets.cpp diff --git a/qad/libs/widgets/plugin/qad_widgets.h b/libs/widgets/plugin/qad_widgets.h similarity index 100% rename from qad/libs/widgets/plugin/qad_widgets.h rename to libs/widgets/plugin/qad_widgets.h diff --git a/qad/libs/widgets/plugin/qcodeeditplugin.cpp b/libs/widgets/plugin/qcodeeditplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/qcodeeditplugin.cpp rename to libs/widgets/plugin/qcodeeditplugin.cpp diff --git a/qad/libs/widgets/plugin/qcodeeditplugin.h b/libs/widgets/plugin/qcodeeditplugin.h similarity index 100% rename from qad/libs/widgets/plugin/qcodeeditplugin.h rename to libs/widgets/plugin/qcodeeditplugin.h diff --git a/qad/libs/widgets/plugin/qipeditplugin.cpp b/libs/widgets/plugin/qipeditplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/qipeditplugin.cpp rename to libs/widgets/plugin/qipeditplugin.cpp diff --git a/qad/libs/widgets/plugin/qipeditplugin.h b/libs/widgets/plugin/qipeditplugin.h similarity index 100% rename from qad/libs/widgets/plugin/qipeditplugin.h rename to libs/widgets/plugin/qipeditplugin.h diff --git a/qad/libs/widgets/plugin/qpiconfigplugin.cpp b/libs/widgets/plugin/qpiconfigplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/qpiconfigplugin.cpp rename to libs/widgets/plugin/qpiconfigplugin.cpp diff --git a/qad/libs/widgets/plugin/qpiconfigplugin.h b/libs/widgets/plugin/qpiconfigplugin.h similarity index 100% rename from qad/libs/widgets/plugin/qpiconfigplugin.h rename to libs/widgets/plugin/qpiconfigplugin.h diff --git a/qad/libs/widgets/plugin/qpiconsoleplugin.cpp b/libs/widgets/plugin/qpiconsoleplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/qpiconsoleplugin.cpp rename to libs/widgets/plugin/qpiconsoleplugin.cpp diff --git a/qad/libs/widgets/plugin/qpiconsoleplugin.h b/libs/widgets/plugin/qpiconsoleplugin.h similarity index 100% rename from qad/libs/widgets/plugin/qpiconsoleplugin.h rename to libs/widgets/plugin/qpiconsoleplugin.h diff --git a/qad/libs/widgets/plugin/qpointeditplugin.cpp b/libs/widgets/plugin/qpointeditplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/qpointeditplugin.cpp rename to libs/widgets/plugin/qpointeditplugin.cpp diff --git a/qad/libs/widgets/plugin/qpointeditplugin.h b/libs/widgets/plugin/qpointeditplugin.h similarity index 100% rename from qad/libs/widgets/plugin/qpointeditplugin.h rename to libs/widgets/plugin/qpointeditplugin.h diff --git a/qad/libs/widgets/plugin/qrecteditplugin.cpp b/libs/widgets/plugin/qrecteditplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/qrecteditplugin.cpp rename to libs/widgets/plugin/qrecteditplugin.cpp diff --git a/qad/libs/widgets/plugin/qrecteditplugin.h b/libs/widgets/plugin/qrecteditplugin.h similarity index 100% rename from qad/libs/widgets/plugin/qrecteditplugin.h rename to libs/widgets/plugin/qrecteditplugin.h diff --git a/qad/libs/widgets/plugin/qvarianteditplugin.cpp b/libs/widgets/plugin/qvarianteditplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/qvarianteditplugin.cpp rename to libs/widgets/plugin/qvarianteditplugin.cpp diff --git a/qad/libs/widgets/plugin/qvarianteditplugin.h b/libs/widgets/plugin/qvarianteditplugin.h similarity index 100% rename from qad/libs/widgets/plugin/qvarianteditplugin.h rename to libs/widgets/plugin/qvarianteditplugin.h diff --git a/qad/libs/widgets/plugin/scroll_spin_boxplugin.cpp b/libs/widgets/plugin/scroll_spin_boxplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/scroll_spin_boxplugin.cpp rename to libs/widgets/plugin/scroll_spin_boxplugin.cpp diff --git a/qad/libs/widgets/plugin/scroll_spin_boxplugin.h b/libs/widgets/plugin/scroll_spin_boxplugin.h similarity index 100% rename from qad/libs/widgets/plugin/scroll_spin_boxplugin.h rename to libs/widgets/plugin/scroll_spin_boxplugin.h diff --git a/qad/libs/widgets/plugin/shortcutsplugin.cpp b/libs/widgets/plugin/shortcutsplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/shortcutsplugin.cpp rename to libs/widgets/plugin/shortcutsplugin.cpp diff --git a/qad/libs/widgets/plugin/shortcutsplugin.h b/libs/widgets/plugin/shortcutsplugin.h similarity index 100% rename from qad/libs/widgets/plugin/shortcutsplugin.h rename to libs/widgets/plugin/shortcutsplugin.h diff --git a/qad/libs/widgets/plugin/spinsliderplugin.cpp b/libs/widgets/plugin/spinsliderplugin.cpp similarity index 100% rename from qad/libs/widgets/plugin/spinsliderplugin.cpp rename to libs/widgets/plugin/spinsliderplugin.cpp diff --git a/qad/libs/widgets/plugin/spinsliderplugin.h b/libs/widgets/plugin/spinsliderplugin.h similarity index 100% rename from qad/libs/widgets/plugin/spinsliderplugin.h rename to libs/widgets/plugin/spinsliderplugin.h diff --git a/qad/libs/widgets/propertystorage_editor.cpp b/libs/widgets/propertystorage_editor.cpp similarity index 100% rename from qad/libs/widgets/propertystorage_editor.cpp rename to libs/widgets/propertystorage_editor.cpp diff --git a/qad/libs/widgets/propertystorage_editor.h b/libs/widgets/propertystorage_editor.h similarity index 100% rename from qad/libs/widgets/propertystorage_editor.h rename to libs/widgets/propertystorage_editor.h diff --git a/qad/libs/widgets/qad_widgets.qrc b/libs/widgets/qad_widgets.qrc similarity index 100% rename from qad/libs/widgets/qad_widgets.qrc rename to libs/widgets/qad_widgets.qrc diff --git a/qad/libs/widgets/qcodeedit.cpp b/libs/widgets/qcodeedit.cpp similarity index 100% rename from qad/libs/widgets/qcodeedit.cpp rename to libs/widgets/qcodeedit.cpp diff --git a/qad/libs/widgets/qcodeedit.h b/libs/widgets/qcodeedit.h similarity index 100% rename from qad/libs/widgets/qcodeedit.h rename to libs/widgets/qcodeedit.h diff --git a/qad/libs/widgets/qcodeedit.ui b/libs/widgets/qcodeedit.ui similarity index 100% rename from qad/libs/widgets/qcodeedit.ui rename to libs/widgets/qcodeedit.ui diff --git a/qad/libs/widgets/qipedit.cpp b/libs/widgets/qipedit.cpp similarity index 100% rename from qad/libs/widgets/qipedit.cpp rename to libs/widgets/qipedit.cpp diff --git a/qad/libs/widgets/qipedit.h b/libs/widgets/qipedit.h similarity index 100% rename from qad/libs/widgets/qipedit.h rename to libs/widgets/qipedit.h diff --git a/qad/libs/widgets/qpiconfignewdialog.cpp b/libs/widgets/qpiconfignewdialog.cpp similarity index 100% rename from qad/libs/widgets/qpiconfignewdialog.cpp rename to libs/widgets/qpiconfignewdialog.cpp diff --git a/qad/libs/widgets/qpiconfignewdialog.h b/libs/widgets/qpiconfignewdialog.h similarity index 100% rename from qad/libs/widgets/qpiconfignewdialog.h rename to libs/widgets/qpiconfignewdialog.h diff --git a/qad/libs/widgets/qpiconfignewdialog.ui b/libs/widgets/qpiconfignewdialog.ui similarity index 100% rename from qad/libs/widgets/qpiconfignewdialog.ui rename to libs/widgets/qpiconfignewdialog.ui diff --git a/qad/libs/widgets/qpiconfigvaluewidget.cpp b/libs/widgets/qpiconfigvaluewidget.cpp similarity index 100% rename from qad/libs/widgets/qpiconfigvaluewidget.cpp rename to libs/widgets/qpiconfigvaluewidget.cpp diff --git a/qad/libs/widgets/qpiconfigvaluewidget.h b/libs/widgets/qpiconfigvaluewidget.h similarity index 100% rename from qad/libs/widgets/qpiconfigvaluewidget.h rename to libs/widgets/qpiconfigvaluewidget.h diff --git a/qad/libs/widgets/qpiconfigwidget.cpp b/libs/widgets/qpiconfigwidget.cpp similarity index 100% rename from qad/libs/widgets/qpiconfigwidget.cpp rename to libs/widgets/qpiconfigwidget.cpp diff --git a/qad/libs/widgets/qpiconfigwidget.h b/libs/widgets/qpiconfigwidget.h similarity index 100% rename from qad/libs/widgets/qpiconfigwidget.h rename to libs/widgets/qpiconfigwidget.h diff --git a/qad/libs/widgets/qpiconsole.cpp b/libs/widgets/qpiconsole.cpp similarity index 100% rename from qad/libs/widgets/qpiconsole.cpp rename to libs/widgets/qpiconsole.cpp diff --git a/qad/libs/widgets/qpiconsole.h b/libs/widgets/qpiconsole.h similarity index 100% rename from qad/libs/widgets/qpiconsole.h rename to libs/widgets/qpiconsole.h diff --git a/qad/libs/widgets/qpointedit.cpp b/libs/widgets/qpointedit.cpp similarity index 100% rename from qad/libs/widgets/qpointedit.cpp rename to libs/widgets/qpointedit.cpp diff --git a/qad/libs/widgets/qpointedit.h b/libs/widgets/qpointedit.h similarity index 100% rename from qad/libs/widgets/qpointedit.h rename to libs/widgets/qpointedit.h diff --git a/qad/libs/widgets/qrectedit.cpp b/libs/widgets/qrectedit.cpp similarity index 100% rename from qad/libs/widgets/qrectedit.cpp rename to libs/widgets/qrectedit.cpp diff --git a/qad/libs/widgets/qrectedit.h b/libs/widgets/qrectedit.h similarity index 100% rename from qad/libs/widgets/qrectedit.h rename to libs/widgets/qrectedit.h diff --git a/qad/libs/widgets/qvariantedit.cpp b/libs/widgets/qvariantedit.cpp similarity index 100% rename from qad/libs/widgets/qvariantedit.cpp rename to libs/widgets/qvariantedit.cpp diff --git a/qad/libs/widgets/qvariantedit.h b/libs/widgets/qvariantedit.h similarity index 100% rename from qad/libs/widgets/qvariantedit.h rename to libs/widgets/qvariantedit.h diff --git a/qad/libs/widgets/qvariantedit_custom.cpp b/libs/widgets/qvariantedit_custom.cpp similarity index 100% rename from qad/libs/widgets/qvariantedit_custom.cpp rename to libs/widgets/qvariantedit_custom.cpp diff --git a/qad/libs/widgets/qvariantedit_custom.h b/libs/widgets/qvariantedit_custom.h similarity index 100% rename from qad/libs/widgets/qvariantedit_custom.h rename to libs/widgets/qvariantedit_custom.h diff --git a/qad/libs/widgets/scroll_spin_box.cpp b/libs/widgets/scroll_spin_box.cpp similarity index 100% rename from qad/libs/widgets/scroll_spin_box.cpp rename to libs/widgets/scroll_spin_box.cpp diff --git a/qad/libs/widgets/scroll_spin_box.h b/libs/widgets/scroll_spin_box.h similarity index 100% rename from qad/libs/widgets/scroll_spin_box.h rename to libs/widgets/scroll_spin_box.h diff --git a/qad/libs/widgets/scroll_spin_box.ui b/libs/widgets/scroll_spin_box.ui similarity index 100% rename from qad/libs/widgets/scroll_spin_box.ui rename to libs/widgets/scroll_spin_box.ui diff --git a/qad/libs/widgets/session_manager.cpp b/libs/widgets/session_manager.cpp similarity index 100% rename from qad/libs/widgets/session_manager.cpp rename to libs/widgets/session_manager.cpp diff --git a/qad/libs/widgets/session_manager.h b/libs/widgets/session_manager.h similarity index 100% rename from qad/libs/widgets/session_manager.h rename to libs/widgets/session_manager.h diff --git a/qad/libs/widgets/shortcuts.cpp b/libs/widgets/shortcuts.cpp similarity index 100% rename from qad/libs/widgets/shortcuts.cpp rename to libs/widgets/shortcuts.cpp diff --git a/qad/libs/widgets/shortcuts.h b/libs/widgets/shortcuts.h similarity index 100% rename from qad/libs/widgets/shortcuts.h rename to libs/widgets/shortcuts.h diff --git a/qad/libs/widgets/spinslider.cpp b/libs/widgets/spinslider.cpp similarity index 100% rename from qad/libs/widgets/spinslider.cpp rename to libs/widgets/spinslider.cpp diff --git a/qad/libs/widgets/spinslider.h b/libs/widgets/spinslider.h similarity index 100% rename from qad/libs/widgets/spinslider.h rename to libs/widgets/spinslider.h diff --git a/logo.png b/logo.png index e08b36a..7ca8e3c 100644 Binary files a/logo.png and b/logo.png differ diff --git a/make_libs.bat b/make_libs.bat deleted file mode 100644 index d530e09..0000000 --- a/make_libs.bat +++ /dev/null @@ -1,6 +0,0 @@ -@echo off -set ARCH=%~1 -set PATH=%SDK_MINGW_DIR%%ARCH%\bin;%SDK_QT4_DIR%%ARCH%\bin;%SDK_CMAKE_DIR%\bin -if defined SDK_QT5_DIR set Qt5_DIR=%SDK_QT5_DIR%%ARCH% -mkdir ..\libs_build_win%ARCH% -cd ../libs_build_win%ARCH% && cmake_mgw -Wno-dev -DQGLVIEW=1 -DQGLENGINE=1 -DQT4=0 ../libs && make install -j4 && cd ../libs && pause diff --git a/make_libs.sh b/make_libs.sh deleted file mode 100755 index ec03987..0000000 --- a/make_libs.sh +++ /dev/null @@ -1,6 +0,0 @@ -#! /bin/bash -cd .. -mkdir libs_build_linux -cd libs_build_linux -cmake ../libs -make install $@ diff --git a/make_libs32.bat b/make_libs32.bat deleted file mode 100644 index c1103ef..0000000 --- a/make_libs32.bat +++ /dev/null @@ -1 +0,0 @@ -make_libs.bat 32 \ No newline at end of file diff --git a/make_libs64.bat b/make_libs64.bat deleted file mode 100644 index f12abc1..0000000 --- a/make_libs64.bat +++ /dev/null @@ -1 +0,0 @@ -make_libs.bat 64 \ No newline at end of file diff --git a/make_libs_all.bat b/make_libs_all.bat deleted file mode 100644 index b6bd18b..0000000 --- a/make_libs_all.bat +++ /dev/null @@ -1,2 +0,0 @@ -start cmd /C make_libs32.bat -start cmd /C make_libs64.bat diff --git a/make_libs_android.bat b/make_libs_android.bat deleted file mode 100644 index 4abfcbb..0000000 --- a/make_libs_android.bat +++ /dev/null @@ -1,6 +0,0 @@ -@echo off -mkdir ..\libs_build_android_%~1 -cd ..\libs_build_android_%~1 -call ..\libs\cmake_android 21 %~1 ..\libs "-DUTILS=0 -DDEBUG=0 -DCMAKE_BUILD_TYPE=Release" -call make install -j4 -cd ..\libs diff --git a/make_libs_android_all.bat b/make_libs_android_all.bat deleted file mode 100644 index b15632e..0000000 --- a/make_libs_android_all.bat +++ /dev/null @@ -1,4 +0,0 @@ -@echo off -for %%a in (x86,x86_64,arm,arm64) do ( - call .\make_libs_android %%a -) diff --git a/pip b/pip deleted file mode 160000 index 3965e54..0000000 --- a/pip +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3965e54e38cbb23e8103e1e09a49910d5b5957b3 diff --git a/piqt/CMakeLists.txt b/piqt/CMakeLists.txt deleted file mode 100644 index 08e8ef9..0000000 --- a/piqt/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -cmake_policy(SET CMP0017 NEW) # need include() with .cmake - -macro(piqt_library NAME _MODULES _LIBS) - _qt_project(${NAME} FALSE "PIQt" "${_MODULES}" "pip;${_LIBS}" ${ARGN}) - _qt_install(${NAME} FALSE "pip" "out_HDR" "out_QM") -endmacro() - -macro(piqt_application NAME _MODULES _LIBS) - _qt_project(${NAME} TRUE "PIQt" "${_MODULES}" "pip;${_LIBS}" ${ARGN}) - _qt_install(${NAME} TRUE "pip" "" "out_QM") -endmacro() - - -include_directories(${PIP_INCLUDES}) -add_subdirectory(libs) -if (UTILS) - add_subdirectory(utils) -endif() - -copy_to_parent(piqt_includes) diff --git a/piqt/LICENSE.txt b/piqt/LICENSE.txt deleted file mode 100644 index 0a04128..0000000 --- a/piqt/LICENSE.txt +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/piqt/libs/CMakeLists.txt b/piqt/libs/CMakeLists.txt deleted file mode 100644 index c20718c..0000000 --- a/piqt/libs/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_directories_with_include("piqt_") diff --git a/piqt/utils/CMakeLists.txt b/piqt/utils/CMakeLists.txt deleted file mode 100644 index 4dbf12d..0000000 --- a/piqt/utils/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_directories("piqt_") diff --git a/project_fs/ProjectFilesystemPlugin.json.in b/project_fs/ProjectFilesystemPlugin.json.in deleted file mode 100644 index 3ae41ba..0000000 --- a/project_fs/ProjectFilesystemPlugin.json.in +++ /dev/null @@ -1,11 +0,0 @@ -{ - \"Name\" : \"ProjectFilesystemPlugin\", - \"Version\" : \"1.1.0\", - \"CompatVersion\" : \"1.1.0\", - \"Vendor\" : \"Peri4\", - \"Copyright\" : \"(C) Peri4\", - \"License\" : \"LGPLv3\", - \"Description\" : \"LGPLv3\", - \"Url\" : \"\", - $$dependencyList -} diff --git a/project_fs/filterdialog.cpp b/project_fs/filterdialog.cpp deleted file mode 100644 index 2137cd1..0000000 --- a/project_fs/filterdialog.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "filterdialog.h" -#include -#include - - -FilterDialog::FilterDialog(QWidget * parent): QDialog(parent) { - setupUi(this); - toolButton->setIcon(Utils::Icons::CLEAN.icon()); - toolButton_2->setIcon(Utils::Icons::CLEAN.icon()); - toolButton_3->setIcon(Utils::Icons::CLEAN.icon()); - toolButton_4->setIcon(Utils::Icons::CLEAN.icon()); -} - - -void FilterDialog::changeEvent(QEvent *e) { - QDialog::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - retranslateUi(this); - break; - default: - break; - } -} - - -FilterDialog::Filter FilterDialog::filter() const { - FilterDialog::Filter ret; - ret.files_show = getFilters(lineFilesShow); - ret.files_hide = getFilters(lineFilesHide); - ret.dirs_show = getFilters(lineDirsShow); - ret.dirs_hide = getFilters(lineDirsHide); - return ret; -} - -void FilterDialog::setFilter(const FilterDialog::Filter & f) { - setFilters(lineFilesShow, f.files_show); - setFilters(lineFilesHide, f.files_hide); - setFilters(lineDirsShow, f.dirs_show); - setFilters(lineDirsHide, f.dirs_hide); -} - - -QStringList FilterDialog::getFilters(QLineEdit * le) const { - if (!le) return QStringList(); - QStringList ret = le->text().split(","); - for (int i = 0; i < ret.size(); ++i) - ret[i] = ret[i].trimmed(); - ret.removeAll(""); - return ret; -} - - -void FilterDialog::setFilters(QLineEdit * le, QStringList f) { - if (!le) return; - le->setText(f.join(",")); -} - - -FilterDialog::Filter::Filter(const QVariant & v) { - QByteArray ba = v.toByteArray(); - if (ba.isEmpty()) return; - QDataStream s(ba); - s >> files_show >> files_hide >> dirs_show >> dirs_hide; -} - - -QVariant FilterDialog::Filter::toVariant() const { - QByteArray ba; - QDataStream s(&ba, QIODevice::ReadWrite); - s << files_show << files_hide << dirs_show << dirs_hide; - return QVariant(ba); -} - - -bool FilterDialog::Filter::filterLogic(const QStringList & fshow, const QStringList & fhide, const QString & path) const { - if (fshow.isEmpty() && fhide.isEmpty()) return true; - if (!fhide.isEmpty()) { - if (QDir::match(fhide, path)) - return false; - else { - if (fshow.isEmpty()) - return true; - else - return QDir::match(fshow, path); - } - } - if (!fshow.isEmpty()) - return QDir::match(fshow, path); - return true; -} diff --git a/project_fs/filterdialog.h b/project_fs/filterdialog.h deleted file mode 100644 index 0d1e2a3..0000000 --- a/project_fs/filterdialog.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef FILTERDIALOG_H -#define FILTERDIALOG_H - -#include "ui_filterdialog.h" - -class FilterDialog: public QDialog, private Ui::FilterDialog -{ - Q_OBJECT -public: - explicit FilterDialog(QWidget *parent = 0); - - struct Filter { - Filter() {} - Filter(const QVariant & v); - QVariant toVariant() const; - bool filterFile(const QString & path) const {return filterLogic(files_show, files_hide, path);} - bool filterDir(const QString & path) const {return filterLogic(dirs_show, dirs_hide, path);} - QStringList files_show; - QStringList files_hide; - QStringList dirs_show; - QStringList dirs_hide; - private: - bool filterLogic(const QStringList & fshow, const QStringList & fhide, const QString & path) const; - }; - - Filter filter() const; - void setFilter(const Filter & f); - -protected: - void changeEvent(QEvent *e); - - QStringList getFilters(QLineEdit * le) const; - void setFilters(QLineEdit * le, QStringList f); - -}; - -#endif // FILTERDIALOG_H diff --git a/project_fs/filterdialog.ui b/project_fs/filterdialog.ui deleted file mode 100644 index df38a3f..0000000 --- a/project_fs/filterdialog.ui +++ /dev/null @@ -1,226 +0,0 @@ - - - FilterDialog - - - - 0 - 0 - 342 - 250 - - - - Project filesystem filters - - - - - - Input filters, separated by ",": - - - - - - - - - Show dirs: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - - - Hide files: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Show files: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - - - Hide dirs: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - lineFilesShow - lineFilesHide - lineDirsShow - lineDirsHide - toolButton - toolButton_2 - toolButton_3 - toolButton_4 - - - - - buttonBox - accepted() - FilterDialog - accept() - - - 259 - 238 - - - 157 - 274 - - - - - buttonBox - rejected() - FilterDialog - reject() - - - 327 - 238 - - - 286 - 274 - - - - - toolButton - clicked() - lineFilesShow - clear() - - - 329 - 60 - - - 269 - 58 - - - - - toolButton_2 - clicked() - lineFilesHide - clear() - - - 329 - 93 - - - 295 - 91 - - - - - toolButton_3 - clicked() - lineDirsShow - clear() - - - 329 - 126 - - - 295 - 124 - - - - - toolButton_4 - clicked() - lineDirsHide - clear() - - - 329 - 159 - - - 295 - 157 - - - - - diff --git a/project_fs/icons/utilities-terminal.png b/project_fs/icons/utilities-terminal.png deleted file mode 100644 index 9c8effe..0000000 Binary files a/project_fs/icons/utilities-terminal.png and /dev/null differ diff --git a/project_fs/projectfilesystem.qrc b/project_fs/projectfilesystem.qrc deleted file mode 100644 index 2b5712f..0000000 --- a/project_fs/projectfilesystem.qrc +++ /dev/null @@ -1,6 +0,0 @@ - - - icons/edit-find.png - icons/utilities-terminal.png - - diff --git a/project_fs/projectfilesystemplugin.cpp b/project_fs/projectfilesystemplugin.cpp deleted file mode 100644 index 37b3c58..0000000 --- a/project_fs/projectfilesystemplugin.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "projectfilesystemplugin.h" -#include "projectfilesystempluginconstants.h" -#include "projectfilesystemwidget.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace ProjectFilesystemPlugin { - namespace Internal { - - ProjectFilesystemPluginPlugin::ProjectFilesystemPluginPlugin() - { - // Create your members - } - - ProjectFilesystemPluginPlugin::~ProjectFilesystemPluginPlugin() - { - // Unregister objects from the plugin manager's object pool - // Delete members - } - - bool ProjectFilesystemPluginPlugin::initialize(const QStringList &arguments, QString *errorString) - { - // Register objects in the plugin manager's object pool - // Load settings - // Add actions to menus - // Connect to other plugins' signals - // In the initialize function, a plugin can be sure that the plugins it - // depends on have initialized their members. - - Q_UNUSED(arguments) - Q_UNUSED(errorString) - - /*auto action = new QAction(tr("ProjectFilesystemPlugin Action"), this); - Core::Command *cmd = Core::ActionManager::registerAction(action, Constants::ACTION_ID, - Core::Context(Core::Constants::C_GLOBAL)); - cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Meta+A"))); - connect(action, &QAction::triggered, this, &ProjectFilesystemPluginPlugin::triggerAction); - - Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::MENU_ID); - menu->menu()->setTitle(tr("ProjectFilesystemPlugin")); - menu->addAction(cmd); - Core::ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(menu); - - qDebug() << Core::IContext::widget();*/ - //addAutoReleasedObject(new ProjectFSWidgetFactory()); - (new ProjectFSWidgetFactory())->setParent(this); - - return true; - } - - void ProjectFilesystemPluginPlugin::extensionsInitialized() - { - Utils::globalMacroExpander()->registerPrefix("ProjectFilesystem", "Project filesystem plugin", [](QString v) -> QString {return v;} ); - Utils::globalMacroExpander()->registerFileVariables("ProjectFilesystem", "Selected item", - []() -> QString { return projectfs_menu_target.absoluteFilePath();}); - // Retrieve objects from the plugin manager's object pool - // In the extensionsInitialized function, a plugin can be sure that all - // plugins that depend on it are completely initialized. - } - - ExtensionSystem::IPlugin::ShutdownFlag ProjectFilesystemPluginPlugin::aboutToShutdown() - { - // Save settings - // Disconnect from signals that are not needed during shutdown - // Hide UI (if you add UI that is not in the main window directly) - return SynchronousShutdown; - } - - void ProjectFilesystemPluginPlugin::triggerAction() - { - QMessageBox::information(Core::ICore::mainWindow(), - tr("Action Triggered"), - tr("This is an action from ProjectFilesystemPlugin.")); - } - - } // namespace Internal -} // namespace ProjectFilesystemPlugin diff --git a/project_fs/projectfilesystemplugin.h b/project_fs/projectfilesystemplugin.h deleted file mode 100644 index 4262865..0000000 --- a/project_fs/projectfilesystemplugin.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "projectfilesystemplugin_global.h" -#include "projectfilesystemwidgetplugin.h" - -#include - -namespace ProjectFilesystemPlugin { - namespace Internal { - - class ProjectFilesystemPluginPlugin : public ExtensionSystem::IPlugin - { - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "ProjectFilesystemPlugin.json") - - public: - ProjectFilesystemPluginPlugin(); - ~ProjectFilesystemPluginPlugin(); - - bool initialize(const QStringList &arguments, QString *errorString); - void extensionsInitialized(); - ShutdownFlag aboutToShutdown(); - - private: - void triggerAction(); - }; - - } // namespace Internal -} // namespace ProjectFilesystemPlugin diff --git a/project_fs/projectfilesystemplugin.pro b/project_fs/projectfilesystemplugin.pro deleted file mode 100644 index ec797d3..0000000 --- a/project_fs/projectfilesystemplugin.pro +++ /dev/null @@ -1,61 +0,0 @@ -DEFINES += PROJECTFILESYSTEMPLUGIN_LIBRARY - -# ProjectFilesystemPlugin files - -SOURCES += projectfilesystemplugin.cpp \ - projectfilesystemwidget.cpp \ - projectfilesystemwidgetplugin.cpp \ - filterdialog.cpp - -HEADERS += projectfilesystemplugin.h \ - projectfilesystemplugin_global.h \ - projectfilesystempluginconstants.h \ - projectfilesystemwidget.h \ - projectfilesystemwidgetplugin.h \ - filterdialog.h - -FORMS += \ - projectfilesystemwidget.ui \ - filterdialog.ui - -RESOURCES += \ - projectfilesystem.qrc - -#QT += network - -# Qt Creator linking - -## Either set the IDE_SOURCE_TREE when running qmake, -## or set the QTC_SOURCE environment variable, to override the default setting -isEmpty(IDE_SOURCE_TREE): IDE_SOURCE_TREE = $$(SDK_QTCREATOR_SRC) - -## Either set the IDE_BUILD_TREE when running qmake, -## or set the QTC_BUILD environment variable, to override the default setting -isEmpty(IDE_BUILD_TREE): IDE_BUILD_TREE = $$(SDK_QTCREATOR_BUILD) - -## uncomment to build plugin into user config directory -## /plugins/ -## where is e.g. -## "%LOCALAPPDATA%\QtProject\qtcreator" on Windows Vista and later -## "$XDG_DATA_HOME/data/QtProject/qtcreator" or "~/.local/share/data/QtProject/qtcreator" on Linux -## "~/Library/Application Support/QtProject/Qt Creator" on OS X -#USE_USER_DESTDIR = yes - -###### If the plugin can be depended upon by other plugins, this code needs to be outsourced to -###### _dependencies.pri, where is the name of the directory containing the -###### plugin's sources. - -QTC_PLUGIN_NAME = ProjectFilesystemPlugin -QTC_LIB_DEPENDS += \ - # nothing here at this time - -QTC_PLUGIN_DEPENDS += \ - coreplugin \ - projectexplorer - -QTC_PLUGIN_RECOMMENDS += \ - # optional plugin dependencies. nothing here at this time - -###### End _dependencies.pri contents ###### - -include($$IDE_SOURCE_TREE/src/qtcreatorplugin.pri) diff --git a/project_fs/projectfilesystemplugin_global.h b/project_fs/projectfilesystemplugin_global.h deleted file mode 100644 index f2e22e8..0000000 --- a/project_fs/projectfilesystemplugin_global.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include - -#if defined(PROJECTFILESYSTEMPLUGIN_LIBRARY) -# define PROJECTFILESYSTEMPLUGINSHARED_EXPORT Q_DECL_EXPORT -#else -# define PROJECTFILESYSTEMPLUGINSHARED_EXPORT Q_DECL_IMPORT -#endif diff --git a/project_fs/projectfilesystempluginconstants.h b/project_fs/projectfilesystempluginconstants.h deleted file mode 100644 index 2fb2893..0000000 --- a/project_fs/projectfilesystempluginconstants.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -namespace ProjectFilesystemPlugin { - namespace Constants { - - const char ACTION_ID[] = "ProjectFilesystemPlugin.Action"; - const char MENU_ID[] = "ProjectFilesystemPlugin.Menu"; - - } // namespace ProjectFilesystemPlugin -} // namespace Constants diff --git a/project_fs/projectfilesystemwidget.cpp b/project_fs/projectfilesystemwidget.cpp deleted file mode 100644 index b858862..0000000 --- a/project_fs/projectfilesystemwidget.cpp +++ /dev/null @@ -1,328 +0,0 @@ -#include "projectfilesystemwidget.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QFileInfo projectfs_menu_target; - - -ProjectFilesystemWidget::ProjectFilesystemWidget(QWidget * parent): QWidget(parent) { - setupUi(this); - in_proc = need_rebuild = false; - int is = style()->pixelMetric(QStyle::PM_ButtonIconSize, 0, this); - label->setFixedSize(is, is); - buttonClear->setIcon(Utils::Icons::CLEAN.icon()); - buttonExpand->setIcon(Utils::Icons::EXPAND.icon()); - buttonCollapse->setIcon(Utils::Icons::COLLAPSE.icon()); - actionOpen_here->setIcon(Utils::Icons::OPENFILE.icon()); - actionOpen_external->setIcon(Utils::Icons::OPENFILE.icon()); - actionShow_external->setIcon(Core::FileIconProvider::icon(QFileIconProvider::Folder)); - actionCopy_name->setIcon(Utils::Icons::COPY.icon()); - actionCopy_path->setIcon(Utils::Icons::COPY.icon()); - popup_menu.addActions(QList() << actionOpen_here << actionOpen_external << actionShow_external << actionOpen_terminal); - popup_menu.addSeparator(); - popup_menu.addActions(QList() << actionCopy_name << actionCopy_path); - proj_plug = 0; - //connect(ProjectExplorer::ProjectTree::instance(), SIGNAL(subtreeChanged(ProjectExplorer::FolderNode*)), this, SLOT(projectsChanged())); - connect(ProjectExplorer::SessionManager::instance(), SIGNAL(startupProjectChanged(ProjectExplorer::Project *)), this, SLOT(startupProjectChanged())); - connect(ProjectExplorer::SessionManager::instance(), SIGNAL(projectAdded(ProjectExplorer::Project*)), this, SLOT(projectsChanged())); - connect(ProjectExplorer::SessionManager::instance(), SIGNAL(projectDisplayNameChanged(ProjectExplorer::Project*)), this, SLOT(projectsChanged())); - connect(ProjectExplorer::SessionManager::instance(), SIGNAL(projectRemoved(ProjectExplorer::Project*)), this, SLOT(projectsChanged())); - //connect(ProjectExplorer::SessionManager::instance(), SIGNAL(), this, SLOT(startupProjectChanged())); - connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)), this, SLOT(fileChanged())); - projectsChanged(); -} - - -void ProjectFilesystemWidget::setCurrentFilter(const FilterDialog::Filter & v) { - cur_filter = v; - projectsChanged(); -} - - -void ProjectFilesystemWidget::changeEvent(QEvent *e) { - QWidget::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - retranslateUi(this); - break; - default: - break; - } -} - - -void ProjectFilesystemWidget::createTree(QTreeWidgetItem * ti, const QString & dir) { - QFileInfoList fl = QDir(dir).entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot, QDir::LocaleAware | QDir::DirsFirst); - checkProcEvents(); - for (QFileInfo i: fl) { - QString nit = i.fileName(); - if (i.isDir()) { - if (!cur_filter.filterDir(nit)) - continue; - } else { - if (!cur_filter.filterFile(nit)) - continue; - } - QTreeWidgetItem * ni = new QTreeWidgetItem(); - ni->setText(0, nit); - ni->setIcon(0, Core::FileIconProvider::icon(i)); - ni->setData(0, Qt::UserRole, i.absoluteFilePath()); - ni->setData(0, Qt::UserRole + 1, i.isDir()); - item_map[i.absoluteFilePath()] = ni; - if (i.isDir()) { - createTree(ni, dir + QDir::separator() + i.fileName()); - } - ti->addChild(ni); - } - //if (ti->childCount() == 0) delete ti; -} - - -bool ProjectFilesystemWidget::filterTree(QTreeWidgetItem * ti, const QString & filter) { - bool ret = false; - for (int i = 0; i < ti->childCount(); ++i) { - QTreeWidgetItem * ci = ti->child(i); - QString cit = ci->text(0); - if (ci->data(0, Qt::UserRole + 1).toBool()) { - if (!filterTree(ci, filter)) { - ci->setHidden(true); - continue; - } - ci->setHidden(false); - ret = true; - } else { - bool f = false; - if (filter.isEmpty()) { - f = true; - } else { - f = f || cit.contains(filter); - } - ci->setHidden(!f); - if (f) ret = true; - } - } - return ret; -} - - -void ProjectFilesystemWidget::filter() { - QString f = lineFilter->text(); - for (int i = 0; i < tree->topLevelItemCount(); ++i) { - QTreeWidgetItem * ti = tree->topLevelItem(i); - filterTree(ti, f); - } -} - - -void ProjectFilesystemWidget::rememberExpanded(QTreeWidgetItem * ti) { - //QMessageBox::information(0, ti->data(0, Qt::UserRole).toString(), QString::number(ti->childCount())); - for (int i = 0; i < ti->childCount(); ++i) { - QTreeWidgetItem * ci = ti->child(i); - if (ci->data(0, Qt::UserRole + 1).toBool()) { - if (ci->isExpanded()) - last_expanded << ci->data(0, Qt::UserRole).toString(); - rememberExpanded(ci); - } - } -} - - -void ProjectFilesystemWidget::restoreExpanded(QTreeWidgetItem * ti) { - for (int i = 0; i < ti->childCount(); ++i) { - QTreeWidgetItem * ci = ti->child(i); - if (ci->data(0, Qt::UserRole + 1).toBool()) { - if (last_expanded.contains(ci->data(0, Qt::UserRole).toString())) - ci->setExpanded(true); - restoreExpanded(ci); - } - } -} - - -void ProjectFilesystemWidget::setExtVariable() { -} - - -void ProjectFilesystemWidget::checkProcEvents() { - if (tm.elapsed() < 10) return; - QApplication::processEvents(); - tm.start(); -} - - -void ProjectFilesystemWidget::projectsChanged() { - if (in_proc) { - need_rebuild = true; - return; - } - in_proc = true; - tm.start(); - last_expanded.clear(); - item_map.clear(); - int spos = tree->verticalScrollBar()->value(); - rememberExpanded(tree->invisibleRootItem()); - tree->clear(); - QApplication::setOverrideCursor(Qt::WaitCursor); - QList pl = ProjectExplorer::SessionManager::projects(); - for (ProjectExplorer::Project * p: pl) { - QTreeWidgetItem * ri = new QTreeWidgetItem(); - QString dir = p->projectDirectory().toString(); - ri->setText(0, p->displayName()); - QFile logo(dir + "/logo.png"); - if (logo.exists()) - ri->setIcon(0, QIcon(logo.fileName())); - else - ri->setIcon(0, Core::FileIconProvider::icon(QFileIconProvider::Folder)); - ri->setData(0, Qt::UserRole, dir); - ri->setData(0, Qt::UserRole + 1, true); - createTree(ri, dir); - tree->addTopLevelItem(ri); - } - startupProjectChanged(); - fileChanged(); - filter(); - restoreExpanded(tree->invisibleRootItem()); - QApplication::restoreOverrideCursor(); - qApp->processEvents(); - tree->verticalScrollBar()->setValue(spos); - in_proc = false; - if (need_rebuild) { - need_rebuild = false; - projectsChanged(); - } -} - - -void ProjectFilesystemWidget::filterClicked() { - filter_dialog.setFilter(cur_filter); - if (filter_dialog.exec() == QDialog::Rejected) return; - setCurrentFilter(filter_dialog.filter()); -} - - -void ProjectFilesystemWidget::fileChanged() { - Core::IDocument * cd = Core::EditorManager::instance()->currentDocument(); - if (!cd) return; - QString np = cd->filePath().toString(); - QTreeWidgetItem * ti = item_map.value(np); - if (!ti) return; - tree->setCurrentItem(ti); - tree->expandItem(ti); -} - - -void ProjectFilesystemWidget::startupProjectChanged() { - ProjectExplorer::Project * sp = ProjectExplorer::SessionManager::startupProject(); - QFont f(tree->font()), bf(f); - bf.setBold(true); - for (int i = 0; i < tree->topLevelItemCount(); ++i) { - QTreeWidgetItem * ti = tree->topLevelItem(i); - ti->setFont(0, f); - if (!sp) continue; - if (sp->projectDirectory().toString() == ti->data(0, Qt::UserRole).toString()) - ti->setFont(0, bf); - } -} - - -void ProjectFilesystemWidget::on_tree_itemDoubleClicked(QTreeWidgetItem * item, int) { - if (!item) return; - QString afp = item->data(0, Qt::UserRole).toString(); - bool dir = item->data(0, Qt::UserRole + 1).toBool(); - if (dir) return; - if (afp.isEmpty()) return; - Core::EditorManager::openEditor(afp); -} - - -void ProjectFilesystemWidget::on_lineFilter_textChanged(const QString & ) { - filter(); -} - - -void ProjectFilesystemWidget::on_tree_itemClicked(QTreeWidgetItem * item, int column) { - projectfs_menu_target = QFileInfo(); - if (!item) { - setExtVariable(); - return; - } - projectfs_menu_target = QFileInfo(item->data(0, Qt::UserRole).toString()); - setExtVariable(); -} - - -void ProjectFilesystemWidget::on_tree_customContextMenuRequested(const QPoint & pos) { - projectfs_menu_target = QFileInfo(); - QTreeWidgetItem * item = tree->itemAt(pos); - //QMessageBox::information(this, "", QString::number(index.row())); - if (!item) { - setExtVariable(); - return; - } - projectfs_menu_target = QFileInfo(item->data(0, Qt::UserRole).toString()); - setExtVariable(); - actionOpen_here->setEnabled(!projectfs_menu_target.isDir()); - actionOpen_external->setEnabled(!projectfs_menu_target.isDir()); - popup_menu.popup(tree->mapToGlobal(pos)); -} - - -void ProjectFilesystemWidget::on_actionOpen_here_triggered() { - if (projectfs_menu_target.path().isEmpty()) return; - Core::EditorManager::openEditor(projectfs_menu_target.absoluteFilePath(), Core::Constants::K_DEFAULT_TEXT_EDITOR_ID); -} - - -void ProjectFilesystemWidget::on_actionOpen_external_triggered() { - if (projectfs_menu_target.path().isEmpty()) return; - QString wd = QDir::current().absolutePath(); - QDir::setCurrent(projectfs_menu_target.absoluteDir().path()); - QDesktopServices::openUrl(QUrl::fromLocalFile(projectfs_menu_target.absoluteFilePath())); - QDir::setCurrent(wd); -} - - -void ProjectFilesystemWidget::on_actionShow_external_triggered() { - if (projectfs_menu_target.path().isEmpty()) return; - Core::FileUtils::showInGraphicalShell(Core::ICore::mainWindow(), projectfs_menu_target.absoluteFilePath()); -} - - -void ProjectFilesystemWidget::on_actionOpen_terminal_triggered() { - if (projectfs_menu_target.path().isEmpty()) return; - Core::FileUtils::openTerminal(QDir(projectfs_menu_target.absoluteFilePath()).path()); -} - - -void ProjectFilesystemWidget::on_actionCopy_name_triggered() { - if (projectfs_menu_target.path().isEmpty()) return; - QApplication::clipboard()->setText(projectfs_menu_target.fileName()); -} - - -void ProjectFilesystemWidget::on_actionCopy_path_triggered() { - if (projectfs_menu_target.path().isEmpty()) return; - QApplication::clipboard()->setText(projectfs_menu_target.absoluteFilePath()); -} diff --git a/project_fs/projectfilesystemwidget.h b/project_fs/projectfilesystemwidget.h deleted file mode 100644 index 0832d95..0000000 --- a/project_fs/projectfilesystemwidget.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef PROJECTFILESYSTEMWIDGET_H -#define PROJECTFILESYSTEMWIDGET_H - -#include "ui_projectfilesystemwidget.h" -#include "filterdialog.h" -#include -#include -#include -#include -#include - -extern QFileInfo projectfs_menu_target; - -class ProjectsModel; - -class ProjectFilesystemWidget: public QWidget, private Ui::ProjectFilesystemWidget -{ - Q_OBJECT -public: - explicit ProjectFilesystemWidget(QWidget * parent = 0); - - FilterDialog::Filter currentFilters() const {return cur_filter;} - QString currentSearch() const {return lineFilter->text();} - - void setCurrentFilter(const FilterDialog::Filter & v); - void setCurrentSearch(QString v) {lineFilter->setText(v);} - -protected: - void changeEvent(QEvent * e); - void createTree(QTreeWidgetItem * ti, const QString & dir); - bool filterTree(QTreeWidgetItem * ti, const QString & filter); - void filter(); - void rememberExpanded(QTreeWidgetItem * ti); - void restoreExpanded(QTreeWidgetItem * ti); - void setExtVariable(); - void checkProcEvents(); - - bool in_proc, need_rebuild; - ExtensionSystem::IPlugin * proj_plug; - QMenu popup_menu; - QMap item_map; - QSet last_expanded; - FilterDialog filter_dialog; - FilterDialog::Filter cur_filter; - QElapsedTimer tm; - -public slots: - void projectsChanged(); - void filterClicked(); - -private slots: - void fileChanged(); - void startupProjectChanged(); - - void on_tree_itemDoubleClicked(QTreeWidgetItem * item, int ); - void on_lineFilter_textChanged(const QString &); - void on_tree_itemClicked(QTreeWidgetItem *item, int column); - void on_tree_customContextMenuRequested(const QPoint & pos); - void on_actionOpen_here_triggered(); - void on_actionOpen_external_triggered(); - void on_actionShow_external_triggered(); - void on_actionOpen_terminal_triggered(); - void on_actionCopy_name_triggered(); - void on_actionCopy_path_triggered(); - -}; - -#endif // PROJECTFILESYSTEMWIDGET_H diff --git a/project_fs/projectfilesystemwidget.ui b/project_fs/projectfilesystemwidget.ui deleted file mode 100644 index c05af68..0000000 --- a/project_fs/projectfilesystemwidget.ui +++ /dev/null @@ -1,183 +0,0 @@ - - - ProjectFilesystemWidget - - - - 0 - 0 - 386 - 390 - - - - - - - - - :/icons/edit-find.png - - - true - - - - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 20 - 20 - - - - - - - - Expand tree - - - - - - - Collapse tree - - - - - - - - - Qt::CustomContextMenu - - - QAbstractItemView::NoEditTriggers - - - Qt::ElideMiddle - - - QAbstractItemView::ScrollPerPixel - - - true - - - true - - - false - - - - Path - - - - - - - - Open as plain - - - - - Open external ... - - - - - Show external ... - - - - - Copy name - - - - - Copy path - - - - - - :/icons/utilities-terminal.png:/icons/utilities-terminal.png - - - Open terminal ... - - - - - - - - - buttonClear - clicked() - lineFilter - clear() - - - 246 - 37 - - - 212 - 35 - - - - - buttonExpand - clicked() - tree - expandAll() - - - 263 - 28 - - - 251 - 58 - - - - - buttonCollapse - clicked() - tree - collapseAll() - - - 307 - 27 - - - 297 - 71 - - - - - diff --git a/project_fs/projectfilesystemwidgetplugin.cpp b/project_fs/projectfilesystemwidgetplugin.cpp deleted file mode 100644 index 48f619c..0000000 --- a/project_fs/projectfilesystemwidgetplugin.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "projectfilesystemwidgetplugin.h" -#include "projectfilesystemwidget.h" -#include -#include -#include -#include - - -ProjectFSWidgetFactory::ProjectFSWidgetFactory() { - setDisplayName(QString::fromLatin1("Project filesystem")); - setId("project_filesystem"); -} - - -Core::NavigationView ProjectFSWidgetFactory::createWidget() { - Core::NavigationView view; - view.widget = new ProjectFilesystemWidget(); - QToolButton * btn = new QToolButton(); - btn->setIcon(Utils::Icons::RELOAD.icon()); - btn->setToolTip(tr("Reload tree")); - view.dockToolBarWidgets << btn; - connect(btn, SIGNAL(clicked()), view.widget, SLOT(projectsChanged())); - btn = new QToolButton(); - btn->setIcon(Utils::Icons::FILTER.icon()); - btn->setToolTip(tr("Setup filters ...")); - view.dockToolBarWidgets << btn; - connect(btn, SIGNAL(clicked()), view.widget, SLOT(filterClicked())); - return view; -} - - -void ProjectFSWidgetFactory::saveSettings(QSettings * settings, int position, QWidget * widget) { - //QMessageBox::information(0, "", QString::fromLatin1(widget->metaObject()->className())); - ProjectFilesystemWidget * w = qobject_cast(widget); - if (!w) return; - settings->beginGroup("ProjectFilesystem"); - settings->beginWriteArray("widget"); - settings->setArrayIndex(position); - settings->setValue("filters", w->currentFilters().toVariant()); - settings->setValue("search", w->currentSearch()); - settings->endArray(); - settings->endGroup(); - settings->sync(); -} - - -void ProjectFSWidgetFactory::restoreSettings(QSettings * settings, int position, QWidget * widget) { - ProjectFilesystemWidget * w = qobject_cast(widget); - if (!w) return; - settings->beginGroup("ProjectFilesystem"); - settings->beginReadArray("widget"); - settings->setArrayIndex(position); - w->setCurrentFilter(FilterDialog::Filter(settings->value("filters", FilterDialog::Filter().toVariant()))); - w->setCurrentSearch(settings->value("search", QString()).toString()); - settings->endArray(); - settings->endGroup(); -} diff --git a/project_fs/projectfilesystemwidgetplugin.h b/project_fs/projectfilesystemwidgetplugin.h deleted file mode 100644 index ccd652d..0000000 --- a/project_fs/projectfilesystemwidgetplugin.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include -#include - - -class ProjectFSWidgetFactory: public Core::INavigationWidgetFactory -{ -public: - ProjectFSWidgetFactory(); - ~ProjectFSWidgetFactory() {} - - Core::NavigationView createWidget(); - - void saveSettings(QSettings * settings, int position, QWidget * widget); - void restoreSettings(QSettings * settings, int position, QWidget * widget); - -}; diff --git a/qad/CMakeLists.txt b/qad/CMakeLists.txt deleted file mode 100644 index 05f1d54..0000000 --- a/qad/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -cmake_policy(SET CMP0017 NEW) # need include() with .cmake -project(qad) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) - -if (NOT DEFINED ANDROID_PLATFORM) - find_package(OpenGL REQUIRED) -endif() -if (MINGW) - find_package(MinGW REQUIRED) -endif() - - -# Version -if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/qad_version.h") - file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/qad_version.h") -endif() -#message(STATUS "Building QAD version ${QAD_VERSION} (${QAD_LIB_TYPE})") - -file(GLOB CMAKES "cmake/*.cmake" "cmake/*.in") - -if (LIB) - install(FILES ${CMAKES} DESTINATION ${CMAKE_ROOT}/Modules) - if (WIN32) - install(FILES ${QAD_VERSION_FILE} DESTINATION ${MINGW_INCLUDE}/qad) - else() - install(FILES ${QAD_VERSION_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/qad) - endif() -else() - install(FILES ${QAD_VERSION_FILE} DESTINATION include/qad) -endif() - -add_subdirectory(libs) -if (UTILS) - add_subdirectory(utils) -endif() - -copy_to_parent(qad_includes) - diff --git a/qad/LICENSE.txt b/qad/LICENSE.txt deleted file mode 100644 index 0a04128..0000000 --- a/qad/LICENSE.txt +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/qad/icons/edit-find.png b/qad/icons/edit-find.png deleted file mode 100644 index 140e581..0000000 Binary files a/qad/icons/edit-find.png and /dev/null differ diff --git a/qglengine/CMakeLists.txt b/qglengine/CMakeLists.txt deleted file mode 100644 index 2d483f9..0000000 --- a/qglengine/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -project(qglengine) -find_package(QAD REQUIRED) -set(_DOMAIN "org.SHS") -set(_COMPANY "SHS") -find_qt(Qt5 Core Gui OpenGL Xml) -if (NOT Qt5) - message(WARNING "Building ${PROJECT_NAME} available only on Qt5!") -else() - find_package(OpenGL REQUIRED) - set_version(qglengine - MAJOR 1 - MINOR 0 - REVISION 0 - BUILD "${BUILD_NUMBER}" - SUFFIX rc - OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/core/qglengine_version.h") - - qt_sources(SRC) - qt_sources(FSRC DIR "formats") - list(APPEND SRC ${FSRC}) - qt_sources(FSRC DIR "core") - list(APPEND SRC ${FSRC}) - qt_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM) - file(GLOB PHS "*_p.h" "formats/*_p.h" "core/*_p.h") - list(REMOVE_ITEM out_HDR "${PHS}") - import_version(qglengine_core qglengine) - set_deploy_property(qglengine_core SHARED - LABEL "QGLEngine core library" - FULLNAME "${_DOMAIN}.qglengine_core" - COMPANY "${_COMPANY}" - INFO "QGLEngine core library") - make_rc(qglengine_core _RC) - qt_add_library(qglengine_core SHARED out_CPP ${_RC}) - qt_generate_export_header(qglengine_core) - list(APPEND out_HDR "${CMAKE_CURRENT_BINARY_DIR}/qglengine_core_export.h") - qt_target_include_directories(qglengine_core PRIVATE ${QAD_INCLUDES} "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/core") - qt_target_link_libraries(qglengine_core qad_utils qad_widgets assimp ${OPENGL_LIBRARIES}) - message(STATUS "Building QGLEngine version ${qglengine_VERSION} (SHARED)") - list(APPEND QT_MULTILIB_LIST qglengine_core) - add_subdirectory(widgets) - copy_to_parent("") - sdk_install("qglengine" FALSE "qglengine_core" "${out_HDR}" "${out_QM}") - if (NOT DEFINED ANDROID_PLATFORM) - if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/plugin") - #add_subdirectory(plugin) - endif() - endif() - - qt_sources(test_SRC DIR "qglview_test") - qt_wrap(${test_SRC} CPPS test_CPP) - qt_add_executable(qglengine_test test_CPP) - qt_target_link_libraries(qglengine_test qglengine_core qglengine_widgets) - qt_target_include_directories(qglengine_test PRIVATE ${QAD_INCLUDES} "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/core" "${CMAKE_CURRENT_SOURCE_DIR}/widgets") -endif() diff --git a/qglengine/LICENSE.txt b/qglengine/LICENSE.txt deleted file mode 100644 index 0a04128..0000000 --- a/qglengine/LICENSE.txt +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/qglengine/coeffs_brdf.png b/qglengine/coeffs_brdf.png deleted file mode 100644 index ec34d28..0000000 Binary files a/qglengine/coeffs_brdf.png and /dev/null differ diff --git a/qglengine/core/glbuffer.cpp b/qglengine/core/glbuffer.cpp deleted file mode 100644 index cd2b503..0000000 --- a/qglengine/core/glbuffer.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - QGL Buffer - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#define GL_GLEXT_PROTOTYPES -#include -#include "glbuffer.h" - - -Buffer::Buffer(GLenum target, GLenum _usage) { - target_ = target; - usage_ = _usage; - buffer_ = 0; - prev_size = 0; -} - - -Buffer::~Buffer() { -} - - -void Buffer::init(QOpenGLExtraFunctions * f) { - if (!isInit()) { - f->glGenBuffers(1, &buffer_); - } -} - - -void Buffer::destroy(QOpenGLExtraFunctions * f) { - if (buffer_ != 0) { - f->glDeleteBuffers(1, &buffer_); - } - buffer_ = 0; -} - - -void Buffer::bind(QOpenGLExtraFunctions * f) { - //qDebug() << "bind" << target_ << buffer_; - f->glBindBuffer(target_, buffer_); -} - - -void Buffer::release(QOpenGLExtraFunctions * f) { - f->glBindBuffer(target_, 0); -} - - -void * Buffer::map(QOpenGLExtraFunctions * f, GLbitfield mode, int size) { - if (size < 0) size = prev_size; - return f->glMapBufferRange(target_, 0, size, mode); -} - - -void Buffer::unmap(QOpenGLExtraFunctions * f) { - f->glUnmapBuffer(target_); -} - - -bool Buffer::resize(QOpenGLExtraFunctions * f, int new_size) { - if (new_size <= 0) return false; - //qDebug() << "check resize buffer" << buffer_ << "bytes" << new_size << ", old =" << prev_size; - if (new_size <= prev_size) return false; - prev_size = new_size; - //qDebug() << "resize buffer " << buffer_ << target_ << "for" << new_size << "bytes"; - f->glBufferData(target_, new_size, 0, usage_); - return true; -} - - -void Buffer::load(QOpenGLExtraFunctions * f, const void * data, int size, int offset) { - if (!data || size <= 0) return; - //qDebug() << "load buffer" << buffer_ << "bytes" << size; - f->glBufferSubData(target_, offset, size, data); -} diff --git a/qglengine/core/glbuffer.h b/qglengine/core/glbuffer.h deleted file mode 100644 index 2cf4c5f..0000000 --- a/qglengine/core/glbuffer.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - QGL Buffer - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLBUFFER_H -#define GLBUFFER_H - -#include "gltypes.h" - - -class Buffer -{ - friend class ObjectBase; -public: - Buffer(GLenum target, GLenum usage = GL_DYNAMIC_DRAW); - ~Buffer(); - - void init (QOpenGLExtraFunctions * f); - void destroy (QOpenGLExtraFunctions * f); - - void bind (QOpenGLExtraFunctions * f); - void release (QOpenGLExtraFunctions * f); - void * map (QOpenGLExtraFunctions * f, GLbitfield mode, int size = -1); - void unmap (QOpenGLExtraFunctions * f); - - // returns true if size changed - bool resize (QOpenGLExtraFunctions * f, int new_size); - void load (QOpenGLExtraFunctions * f, const void * data, int size, int offset = 0); - - GLuint ID() const {return buffer_;} - GLenum usage() const {return usage_;} - GLenum target() const {return target_;} - void setTarget(GLenum t) {target_ = t;} - bool isInit() const {return buffer_ != 0;} - -private: - GLenum target_, usage_; - GLuint buffer_; - int prev_size; - -}; - - -#endif // GLBUFFER_H diff --git a/qglengine/core/glcubemap.cpp b/qglengine/core/glcubemap.cpp deleted file mode 100644 index 19b8750..0000000 --- a/qglengine/core/glcubemap.cpp +++ /dev/null @@ -1,281 +0,0 @@ -/* - QGL CubeTexture - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "gltypes.h" -#include "glcubemap.h" -#include "hdr_p.h" - -using namespace QGLEngineShaders; - - -QVector loadFileHDR(const QString & path, QSize * size) { - if (size) *size = QSize(); - QVector ret; - QFile f(path); - if (!f.open(QIODevice::ReadOnly)) { - qDebug() << "[QGLEngine] Can`t open" << path; - return ret; - } - QTextStream ts(&f); - QString line = ts.readLine(256); - if (line != "#?RADIANCE") return ret; - QSize sz; - while (!ts.atEnd()) { - line = ts.readLine(256); - if (line.startsWith("FORMAT")) { - line.remove(0, 7); - if (!line.startsWith("32-bit")) { - qDebug() << "[QGLEngine] File" << path << "has unknown format!"; - return ret; - } - } - if (line.mid(1, 2) == "Y ") { - QStringList sl = line.trimmed().split(" "); - sl.removeAll(""); - if (sl.size() != 4) { - qDebug() << "[QGLEngine] File" << path << "has unknown size!"; - return ret; - } - sz.setWidth (sl[3].toInt()); - sz.setHeight(sl[1].toInt()); - //qDebug() << "found size" << sz; - break; - } - } - if (sz.isEmpty()) return ret; - f.seek(ts.pos()); - QDataStream ds(&f); - int count = sz.width() * sz.height(); - QVector data(count*3); - if (!RGBE_ReadPixels_RLE(&ds, data.data(), sz.width(), sz.height())) - return ret; - - if (size) *size = sz; - ret.resize(count); - //QColor col; - //QImage im(sz, QImage::Format_ARGB32); - //QRgb * imdata = (QRgb*)im.bits(); - for (int i = 0; i < count; ++i) { - QVector3D p(pow(data[i*3 + 2], 1. / 2.2), - pow(data[i*3 + 1], 1. / 2.2), - pow(data[i*3 + 0], 1. / 2.2)); - ret[i] = p; - //col = QColor::fromRgbF(piClamp(p[0], 0.f, 1.f), - // piClamp(p[1], 0.f, 1.f), - // piClamp(p[2], 0.f, 1.f)); - //imdata[i] = col.rgb(); - } - //im.save("_hdr.png"); - - return ret; -} - - -//#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 -//#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 -//#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 -//#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 -//#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 -//#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A -QVector faceHDR(const QVector & data, QSize sz, QSize & fsz, int face) { - QVector ret; - if (data.isEmpty() || sz.isNull()) return ret; - QRect fr; - int fw = sz.width () / 4; - int fh = sz.height() / 3; - fsz = QSize(fw, fh); - ret.reserve(fw * fh); - switch (face) { - case GL_TEXTURE_CUBE_MAP_POSITIVE_X: - fr.setRect(fw, fh, fw, fh); - for (int x = fr.left(); x <= fr.right(); ++x) { - for (int y = fr.top(); y <= fr.bottom(); ++y) { - ret << data[y*sz.width() + x]; - } - } - break; - case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: - fr.setRect(fw*3, fh, fw, fh); - for (int x = fr.right(); x >= fr.left(); --x) { - for (int y = fr.bottom(); y >= fr.top(); --y) { - ret << data[y*sz.width() + x]; - } - } - break; - case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: - fr.setRect( 0, fh, fw, fh); - for (int y = fr.bottom(); y >= fr.top(); --y) { - for (int x = fr.left(); x <= fr.right(); ++x) { - ret << data[y*sz.width() + x]; - } - } - break; - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: - fr.setRect(fw*2, fh, fw, fh); - for (int y = fr.top(); y <= fr.bottom(); ++y) { - for (int x = fr.right(); x >= fr.left(); --x) { - ret << data[y*sz.width() + x]; - } - } - break; - case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: - fr.setRect(fw, 0, fw, fh); - for (int x = fr.left(); x <= fr.right(); ++x) { - for (int y = fr.top(); y <= fr.bottom(); ++y) { - ret << data[y*sz.width() + x]; - } - } - break; - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: - fr.setRect(fw, fh*2, fw, fh); - for (int x = fr.left(); x <= fr.right(); ++x) { - for (int y = fr.top(); y <= fr.bottom(); ++y) { - ret << data[y*sz.width() + x]; - } - } - break; - default: break; - } - if (fr.isEmpty()) return ret; - //qDebug() << ret.size() << fr; - return ret; -} - - - -CubeTexture::CubeTexture(QOpenGLExtraFunctions * f_, int _size, const GLenum & _format): f(f_) { - size = _size; - format_ = _format; - id_ = 0; - changed_ = false; -} - - -bool CubeTexture::init() { - if (isInit()) return true; - f->glGenTextures(1, &id_); - f->glBindTexture(GL_TEXTURE_CUBE_MAP, id_); - f->glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - f->glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - f->glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); - f->glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - f->glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - //glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); - //glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); - //glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); - //glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); - //glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); - //glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); - //glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); - changed_ = false; - return id_ > 0; -} - - -void CubeTexture::destroy() { - if (!isInit()) return; - f->glDeleteTextures(1, &id_); - id_ = 0; -} - - -void CubeTexture::bind(int channel) { - init(); - f->glActiveTexture(GL_TEXTURE0 + channel); - f->glBindTexture(GL_TEXTURE_CUBE_MAP, id_); -} - - -void CubeTexture::release() { - f->glBindTexture(GL_TEXTURE_CUBE_MAP, 0); -} - - -void CubeTexture::loadHDR(const QVector & data, QSize sz) { - bind(); - QSize fsz; - QVector fd; - for (int i = 0; i < 6; ++i) { - fd = faceHDR(data, sz, fsz, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i); - //qDebug() << "load cube" << fd[0]; - //f->glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - f->glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, format_, fsz.width(), fsz.height(), 0, GL_RGB, GL_FLOAT, fd.isEmpty() ? 0 : fd.constData()); - //qDebug() << QString::number(GetLastError(), 16); - } - f->glGenerateMipmap(GL_TEXTURE_CUBE_MAP); -} - - -void CubeTexture::setFileHDR(const QString & path) { - hdr_path = path; - changed_ = true; -} - - -void CubeTexture::load() { - if (!changed_) return; - init(); - if (!hdr_path.isEmpty()) { - QSize sz; - QVector data = loadFileHDR(hdr_path, &sz); - loadHDR(data, sz); - } else { - destroy(); - bind(); - for (int i = 0; i < 6; ++i) { - f->glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, format_, 1, 1, 0, GL_RGB, GL_FLOAT, 0); - } - f->glGenerateMipmap(GL_TEXTURE_CUBE_MAP); - } - changed_ = false; -} - -/* -void CubeTexture::load() { - if (isEmpty()) return; - create(); - if (!path(0).isEmpty()) loadFront(path(0)); - if (!path(1).isEmpty()) loadBack(path(1)); - if (!path(2).isEmpty()) loadLeft(path(2)); - if (!path(3).isEmpty()) loadRight(path(3)); - if (!path(4).isEmpty()) loadTop(path(4)); - if (!path(5).isEmpty()) loadBottom(path(5)); -} - - -void CubeTexture::loadFromDirectory(const QString & dir) { - QDir d(dir); QFileInfoList sl; - sl = d.entryInfoList(QStringList("front.*"), QDir::Files | QDir::NoDotAndDotDot); if (!sl.isEmpty()) loadFront(sl[0].absoluteFilePath()); - sl = d.entryInfoList(QStringList("back.*"), QDir::Files | QDir::NoDotAndDotDot); if (!sl.isEmpty()) loadBack(sl[0].absoluteFilePath()); - sl = d.entryInfoList(QStringList("left.*"), QDir::Files | QDir::NoDotAndDotDot); if (!sl.isEmpty()) loadLeft(sl[0].absoluteFilePath()); - sl = d.entryInfoList(QStringList("right.*"), QDir::Files | QDir::NoDotAndDotDot); if (!sl.isEmpty()) loadRight(sl[0].absoluteFilePath()); - sl = d.entryInfoList(QStringList("top.*"), QDir::Files | QDir::NoDotAndDotDot); if (!sl.isEmpty()) loadTop(sl[0].absoluteFilePath()); - sl = d.entryInfoList(QStringList("bottom.*"), QDir::Files | QDir::NoDotAndDotDot); if (!sl.isEmpty()) loadBottom(sl[0].absoluteFilePath()); -} - - -void CubeTexture::loadPathesFromDirectory(const QString & dir) { - QDir d(dir); QFileInfoList sl; - sl = d.entryInfoList(QStringList("front.*"), QDir::Files | QDir::NoDotAndDotDot); if (!sl.isEmpty()) pathes[0] = sl[0].absoluteFilePath(); - sl = d.entryInfoList(QStringList("back.*"), QDir::Files | QDir::NoDotAndDotDot); if (!sl.isEmpty()) pathes[1] = sl[0].absoluteFilePath(); - sl = d.entryInfoList(QStringList("left.*"), QDir::Files | QDir::NoDotAndDotDot); if (!sl.isEmpty()) pathes[2] = sl[0].absoluteFilePath(); - sl = d.entryInfoList(QStringList("right.*"), QDir::Files | QDir::NoDotAndDotDot); if (!sl.isEmpty()) pathes[3] = sl[0].absoluteFilePath(); - sl = d.entryInfoList(QStringList("top.*"), QDir::Files | QDir::NoDotAndDotDot); if (!sl.isEmpty()) pathes[4] = sl[0].absoluteFilePath(); - sl = d.entryInfoList(QStringList("bottom.*"), QDir::Files | QDir::NoDotAndDotDot); if (!sl.isEmpty()) pathes[5] = sl[0].absoluteFilePath(); -} -*/ diff --git a/qglengine/core/glcubemap.h b/qglengine/core/glcubemap.h deleted file mode 100644 index 6f5ed5d..0000000 --- a/qglengine/core/glcubemap.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - QGL CubeTexture - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLCUBEMAP_H -#define GLCUBEMAP_H - -#include "glshaders_types.h" -#include "chunkstream.h" - -QVector loadFileHDR(const QString & path, QSize * size = 0); - -class CubeTexture { -public: - CubeTexture(QOpenGLExtraFunctions * f_, int _size, const GLenum & _format = GL_RGB16F); - bool init(); - void destroy(); - void bind(int channel = 0); - void release(); - void resize(int _size) {size = _size; changed_ = true;} - void loadHDR(const QVector & data, QSize sz); - void setFileHDR(const QString & path); - QString fileHDR() const {return hdr_path;} - //void loadFromDirectory(const QString & dir); - //void loadFront(const QString & path) {bind(); pathes[0] = path; createGLTexture(id_, rotateQImageLeft(QImage(path)).scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), format_, GL_TEXTURE_CUBE_MAP_POSITIVE_X);} - //void loadBack(const QString & path) {bind(); pathes[1] = path; createGLTexture(id_, rotateQImageRight(QImage(path)).scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), format_, GL_TEXTURE_CUBE_MAP_NEGATIVE_X);} - //void loadLeft(const QString & path) {bind(); pathes[2] = path; createGLTexture(id_, QImage(path).scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), format_, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y);} - //void loadRight(const QString & path) {bind(); pathes[3] = path; createGLTexture(id_, rotateQImage180(QImage(path)).scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), format_, GL_TEXTURE_CUBE_MAP_POSITIVE_Y);} - //void loadTop(const QString & path) {bind(); pathes[4] = path; createGLTexture(id_, rotateQImageLeft(QImage(path)).scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), format_, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);} - //void loadBottom(const QString & path) {bind(); pathes[5] = path; createGLTexture(id_, rotateQImageLeft(QImage(path)).scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), format_, GL_TEXTURE_CUBE_MAP_POSITIVE_Z);} - //void load(); - //bool isEmpty() const {foreach (const QString & i, pathes) if (!i.isEmpty()) return false; return true;} - GLenum format() const {return format_;} - void setFormat(GLenum f) {format_ = f; changed_ = true;} - GLuint id() const {return id_;} - bool isInit() const {return id_ != 0;} - //const QString & path(int side) const {return pathes[side];} - //void setPath(int side, const QString & p) {pathes[side] = p;} - //void loadPathesFromDirectory(const QString & dir); - void load(); -private: - - QOpenGLExtraFunctions * f; - bool changed_; - int size; - GLenum format_; - GLuint id_; - QString hdr_path; - //QVector pathes; -}; - - -#endif // GLCUBEMAP_H diff --git a/qglengine/core/glframebuffer.cpp b/qglengine/core/glframebuffer.cpp deleted file mode 100644 index 88e5c92..0000000 --- a/qglengine/core/glframebuffer.cpp +++ /dev/null @@ -1,315 +0,0 @@ -/* - QGL Framebuffer - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include -#include "glframebuffer.h" -#include - - -Framebuffer::Framebuffer(QOpenGLExtraFunctions * f_, int colorAttachments_, bool withDepth, GLenum colorFormat_, GLenum _target): f(f_), - pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) { - is_depth = withDepth; - target_ = _target; - color_formats.fill(colorFormat_, colorAttachments_); - colors.fill(0, colorAttachments_); - fbo = drbo = 0; - tex_d = 0; - wid = hei = 0; - pbo_queried = 0; - is_changed = false; -} - - -Framebuffer::Framebuffer(QOpenGLExtraFunctions * f_, QVector colors_, bool withDepth, GLenum _target): f(f_), - pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) { - is_depth = withDepth; - target_ = _target; - color_formats = colors_; - colors.fill(0, colors_.size()); - fbo = drbo = 0; - tex_d = 0; - wid = hei = 0; - pbo_queried = 0; - is_changed = false; -} - - -Framebuffer::~Framebuffer() { - deleteGLFramebuffer(fbo); - deleteGLRenderbuffer(drbo); - for (int i = 0; i < colors.size(); ++i) - deleteGLTexture(f, colors[i]); - deleteGLTexture(f, tex_d); -} - - -void Framebuffer::resize(int width, int height, bool force) { - if ((wid == width) && (hei == height) && !force) return; - wid = width; - hei = height; - deleteGLFramebuffer(fbo); - f->glGenFramebuffers(1, &fbo); - f->glBindFramebuffer(GL_FRAMEBUFFER, fbo); - for (int i = 0; i < colors.size(); ++i) { - deleteGLTexture(f, colors[i]); - createGLTexture(f, colors[i], width, height, color_formats[i], target_); - f->glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - f->glTexParameteri(target_, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - f->glTexParameteri(target_, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - f->glTexParameteri(target_, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - f->glTexParameteri(target_, GL_TEXTURE_MAX_LEVEL, 4); - //f->glTexParameteri(target_, GL_GENERATE_MIPMAP_SGIS, GL_FALSE); - f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, target_, colors[i], 0); - } - if (is_depth) { - deleteGLTexture(f, tex_d); - deleteGLRenderbuffer(drbo); - f->glGenRenderbuffers(1, &drbo); - f->glBindRenderbuffer(GL_RENDERBUFFER, drbo); - f->glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height); - f->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, drbo); - createGLTexture(f, tex_d, width, height, GL_DEPTH_COMPONENT); - f->glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - f->glTexParameteri(target_, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - f->glTexParameteri(target_, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - f->glTexParameteri(target_, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - //f->glTexParameteri(target_, GL_GENERATE_MIPMAP_SGIS, GL_FALSE); - f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, target_, tex_d, 0); - } - f->glBindFramebuffer(GL_FRAMEBUFFER, 0); - if (pbo.isInit()) { - enablePixelBuffer(); - } - is_changed = false; -} - - -QImage Framebuffer::grab() const { - return QImage(); -} - - -void Framebuffer::queryPoint(int index, QPoint p) { - pbo_queried = 0; - if (index < 0 || index >= colors.size()) return; - if (!rect().contains(p) || !pbo.isInit()) return; - f->glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); - f->glReadBuffer(GL_COLOR_ATTACHMENT0 + index); - pbo.bind(f); - f->glReadPixels(p.x(), height() - p.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 0); - pbo_queried = 1; - pbo.release(f); -} - - -void Framebuffer::queryPoints(int index, QRect rect_, GLenum pixel_format) { - pbo_queried = 0; - if (index < 0 || index >= colors.size()) return; - rect_ &= rect(); - if (rect_.isEmpty() || !pbo.isInit()) return; - f->glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); - f->glReadBuffer(GL_COLOR_ATTACHMENT0 + index); - pbo.bind(f); - f->glReadPixels(rect_.x(), height() - rect_.bottom(), rect_.width(), rect_.height(), GL_RGBA, pixel_format, 0); - pbo_queried = rect_.width() * rect_.height(); - pbo.release(f); -} - - -void Framebuffer::queryImage(int index) { - queryPoints(index, rect()); -} - - -uint Framebuffer::getPoint() const { - if (!pbo.isInit() || (pbo_queried == 0)) return 0; - uint ret = 0; - pbo.bind(f); - void * map = pbo.map(f, GL_MAP_READ_BIT, sizeof(uint)); - if (map) - memcpy(&ret, map, sizeof(uint)); - pbo.unmap(f); - pbo.release(f); - return ret; -} - - -QVector Framebuffer::getPointsByte() const { - QVector ret; - if (!pbo.isInit() || (pbo_queried == 0)) return ret; - ret.resize(pbo_queried); - pbo.bind(f); - void * map = pbo.map(f, GL_MAP_READ_BIT, pbo_queried * sizeof(uint)); - if (map) - memcpy(ret.data(), map, pbo_queried * sizeof(uint)); - pbo.unmap(f); - pbo.release(f); - return ret; -} - - -QVector Framebuffer::getPointsFloat() const { - QVector ret; - if (!pbo.isInit() || (pbo_queried == 0)) return ret; - ret.resize(pbo_queried); - pbo.bind(f); - void * map = pbo.map(f, GL_MAP_READ_BIT, pbo_queried * sizeof(QVector4D)); - if (map) - memcpy(ret.data(), map, pbo_queried * sizeof(QVector4D)); - pbo.unmap(f); - pbo.release(f); - return ret; -} - - -QImage Framebuffer::getImage() const { - QImage ret; - if (!pbo.isInit() || (pbo_queried == 0)) return ret; - ret = QImage(size(), QImage::Format_RGBA8888); - int bytes = width() * height() * 4; - pbo.bind(f); - void * map = pbo.map(f, GL_MAP_READ_BIT, bytes); - if (map) - memcpy(ret.bits(), map, bytes); - pbo.unmap(f); - pbo.release(f); - return ret; -} - - -QVector Framebuffer::grabF(int index) const { - QVector ret; - if (index < 0 || index >= colors.size()) return ret; - f->glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); - f->glReadBuffer(GL_COLOR_ATTACHMENT0 + index); - ret.resize(wid * hei * 4); - f->glReadPixels(0, 0, wid, hei, GL_RGBA, GL_FLOAT, ret.data()); - return ret; -} - - -void Framebuffer::blit(int index_from, GLuint fb_to, int index_to, QRect from, QRect to, GLbitfield mask, GLenum filter) const { - if (index_from < 0 || index_from >= colors.size()) return; - GLenum e = GL_COLOR_ATTACHMENT0 + index_to; - f->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb_to); - f->glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); - f->glReadBuffer(GL_COLOR_ATTACHMENT0 + index_from); - f->glDrawBuffers(1, &e); - f->glBlitFramebuffer(from.x(), from.y(), from.right(), from.bottom(), to.x(), to.y(), to.right(), to.bottom(), mask, filter); -} - - -void Framebuffer::bind() { - if (is_changed) resize(wid, hei); - if (fbo == 0) return; - f->glGetIntegerv(GL_VIEWPORT, prev_view); - f->glBindFramebuffer(GL_FRAMEBUFFER, fbo); - setWriteBuffers(); - f->glReadBuffer(GL_COLOR_ATTACHMENT0); - f->glViewport(0, 0, wid, hei); -} - - -void Framebuffer::release() { - is_changed = false; - if (fbo == 0) return; - f->glBindFramebuffer(GL_FRAMEBUFFER, 0); - f->glViewport(prev_view[0], prev_view[1], prev_view[2], prev_view[3]); -} - - -void Framebuffer::setWriteBuffer(int index) { - unsetWriteBuffers(); - GLenum e = GL_COLOR_ATTACHMENT0 + index; - f->glDrawBuffers(1, &e); -} - - -void Framebuffer::setWriteBuffers(const int * indeces, int count) { - unsetWriteBuffers(); - QVector buffers; - for (int i = 0; i < count; ++i) - buffers << GL_COLOR_ATTACHMENT0 + indeces[i]; - f->glDrawBuffers(buffers.size(), buffers.constData()); -} - - -void Framebuffer::setWriteBuffers() { - QVector buffers; - for (int i = 0; i < colors.size(); ++i) - buffers << GL_COLOR_ATTACHMENT0 + i; - f->glDrawBuffers(buffers.size(), buffers.constData()); -} - - -void Framebuffer::unsetWriteBuffers() { - QVector buffers(colors.size(), GL_NONE); - f->glDrawBuffers(buffers.size(), buffers.constData()); -} - - -void Framebuffer::enablePixelBuffer() { - pbo.init(f); - pbo.bind(f); - pbo.resize(f, width()*height()*4*4); - pbo.release(f); -} - - -void Framebuffer::setColorTextureFiltering(int index, GLenum filter) { - bindColorTexture(index); - f->glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, filter); - f->glTexParameteri(target_, GL_TEXTURE_MAG_FILTER, filter); -} - - -void Framebuffer::bindColorTexture(int index, int channel) { - if (index < 0 || index >= colors.size()) return; - f->glActiveTexture(GL_TEXTURE0 + channel); - f->glBindTexture(GL_TEXTURE_2D, colors[index]); -} - - -void Framebuffer::bindColorTextures() { - for (int i = colors.size() - 1; i >= 0; --i) { - f->glActiveTexture(GL_TEXTURE0 + i); - f->glBindTexture(GL_TEXTURE_2D, colors[i]); - //f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - //f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - } -} - - -void Framebuffer::bindDepthTexture(int channel) { - f->glActiveTexture(GL_TEXTURE0 + channel); - f->glBindTexture(GL_TEXTURE_2D, tex_d); -} - - -void Framebuffer::deleteGLRenderbuffer(GLuint & drbo) { - if (drbo != 0) - f->glDeleteRenderbuffers(1, &drbo); - drbo = 0; -} - - -void Framebuffer::deleteGLFramebuffer(GLuint & fbo) { - if (fbo != 0) - f->glDeleteFramebuffers(1, &fbo); - fbo = 0; -} diff --git a/qglengine/core/glframebuffer.h b/qglengine/core/glframebuffer.h deleted file mode 100644 index cc6549e..0000000 --- a/qglengine/core/glframebuffer.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - QGL Framebuffer - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLFRAMEBUFFER_H -#define GLFRAMEBUFFER_H - -#include "glbuffer.h" - - -class Framebuffer -{ - friend class FramebufferMipmap; -public: - Framebuffer(QOpenGLExtraFunctions * f_, int colorAttachments = 1, bool withDepth = true, GLenum colorFormat = GL_RGBA8, GLenum _target = GL_TEXTURE_2D); - Framebuffer(QOpenGLExtraFunctions * f_, QVector colors_, bool withDepth = true, GLenum _target = GL_TEXTURE_2D); - virtual ~Framebuffer(); - - GLuint id() const {return fbo;} - GLuint colorTexture(int index = 0) const {return colors[index];} - //GLenum colorFormat() const {return color_format;} - GLuint depthTexture() const {return tex_d;} - GLenum target() const {return target_;} - bool isInit() const {return fbo != 0;} - int width() const {return wid;} - int height() const {return hei;} - QSize size() const {return QSize(wid, hei);} - QRect rect() const {return QRect(0, 0, wid, hei);} - QImage grab() const; - QVector grabF(int index) const; - void queryPoint(int index, QPoint p); - void queryPoints(int index, QRect rect, GLenum pixel_format = GL_UNSIGNED_BYTE); - void queryImage(int index); - uint getPoint() const; - QVector getPointsByte() const; - QVector getPointsFloat() const; - QImage getImage() const; - int queriedPoints() const {return pbo_queried;} - void blit(int index_from, GLuint fb_to, int index_to, QRect from, QRect to, GLbitfield mask = GL_COLOR_BUFFER_BIT, GLenum filter = GL_NEAREST) const; - - void resize(int width, int height, bool force = false); - void bind(); - void release(); - void setReadBuffer(int index) {glReadBuffer(GL_COLOR_ATTACHMENT0 + index);} - void setWriteBuffer(int index); - void setWriteBuffers(const int * indeces, int count); - void setWriteBuffers(const QVector & indeces) {setWriteBuffers(indeces.constData(), indeces.size());} - void setWriteBuffers(); - void unsetWriteBuffers(); - //void setColorFormat(GLenum format) {color_format = format; is_changed = true;} - void enablePixelBuffer(); - void setColorTextureFiltering(int index, GLenum filter); - - void copyDepthFrom(GLuint tex) {;} - void bindColorTexture(int index, int channel = 0); - void bindColorTextures(); - void bindDepthTexture(int channel); - -private: - void deleteGLRenderbuffer(GLuint & drbo); - void deleteGLFramebuffer(GLuint & fbo); - - bool is_depth, is_changed; - int pbo_queried; - QOpenGLExtraFunctions * f; - mutable Buffer pbo; - QVector colors; - QVector color_formats; - GLenum target_; - GLuint fbo, drbo, tex_d; - GLint prev_view[4], wid, hei; - -}; - -#endif // GLFRAMEBUFFER_H diff --git a/qglengine/core/glframebuffer_mipmap.cpp b/qglengine/core/glframebuffer_mipmap.cpp deleted file mode 100644 index 6a38962..0000000 --- a/qglengine/core/glframebuffer_mipmap.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - QGL FramebufferMipmap - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include -#include "glframebuffer_mipmap.h" -#include - - -FramebufferMipmap::FramebufferMipmap(const Framebuffer & fb, int index_from_, int levels): src_fb(fb) { - index_from = index_from_; - for (int i = 0; i < levels; ++i) - fbo << new Framebuffer(fb.f, 1, false, fb.color_formats[index_from]); -} - - -FramebufferMipmap::~FramebufferMipmap() { - -} - - -void FramebufferMipmap::resize() { - QSize sz = src_fb.size(); - for (int i = 0; i < fbo.size(); ++i) { - sz /= 2; - fbo[i]->resize(sz.width(), sz.height()); - } -} - - -void FramebufferMipmap::create() { - if (fbo.isEmpty()) return; - src_fb.blit(index_from, fbo[0]->id(), 0, src_fb.rect(), fbo[0]->rect(), GL_COLOR_BUFFER_BIT, GL_LINEAR); - for (int i = 0; i < fbo.size() - 1; ++i) - fbo[i]->blit(0, fbo[i + 1]->id(), 0, fbo[i]->rect(), fbo[i + 1]->rect(), GL_COLOR_BUFFER_BIT, GL_LINEAR); -} diff --git a/qglengine/core/glframebuffer_mipmap.h b/qglengine/core/glframebuffer_mipmap.h deleted file mode 100644 index 1bd9781..0000000 --- a/qglengine/core/glframebuffer_mipmap.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - QGL FramebufferMipmap - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLFRAMEBUFFER_MIPMAP_H -#define GLFRAMEBUFFER_MIPMAP_H - -#include "glframebuffer.h" - - -class FramebufferMipmap -{ -public: - FramebufferMipmap(const Framebuffer & fb, int index_from_, int levels = 2); - virtual ~FramebufferMipmap(); - - int levelsCount() const {return fbo.size();} - int lastLevel() const {return fbo.size() - 1;} - Framebuffer & plane(int level) {return *fbo[level];} - Framebuffer & lastPlane() {return *fbo[lastLevel()];} - int width (int level) const {return fbo[level]->wid;} - int height(int level) const {return fbo[level]->hei;} - QSize size(int level) const {return fbo[level]->size();} - QRect rect(int level) const {return fbo[level]->rect();} - - void resize(); - void create(); - -private: - int index_from; - const Framebuffer & src_fb; - QVector fbo; - -}; - -#endif // GLFRAMEBUFFER_MIPMAP_H diff --git a/qglengine/core/glmaterial.cpp b/qglengine/core/glmaterial.cpp deleted file mode 100644 index 7afb341..0000000 --- a/qglengine/core/glmaterial.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - QGL Material - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "gltypes.h" -#include "gltexture_manager.h" -#include "qglview.h" - -using namespace QGLEngineShaders; - - -Map::Map() { - bitmap_id = 0; - color_amount = 1.f; - color_offset = 0.f; - bitmap_scale = QPointF(1., 1.); - use_bitmap = false; - _changed = true; - _layer = 0; -} - - -void Map::setBitmapPath(const QString & p) { - bitmap_path = p; - _changed = true; -} - - -void Map::load(TextureManager * tm) { - if (bitmap_id == 0) - bitmap_id = tm->loadTexture(bitmap_path, true, _type == mtNormal); -} - - -void Map::copyToQGLMap(QGLMap & m) const { - m.amount = color_amount; - m.offset = color_offset; - m.scale = QVector2D(bitmap_scale); - if (hasBitmap() && use_bitmap) { - m.array_index = tarMaps; - m.map_index = _layer; - } else { - m.array_index = tarEmpty; - m.map_index = (_type == mtNormal ? emrBlue : emrWhite); - } -} - - - - -Material::Material(const QString _name)/*: map_reflection(512)*/ { - setTypes(); - name = _name; - color_diffuse = Qt::white; - color_emission = Qt::black; - glass = false; - transparency = reflectivity = 0.f; - map_roughness.color_amount = 0.75f; - map_metalness.color_amount = 0.25f; - iof = 1.f; - dispersion = 0.05f; - _changed = true; - _index = 0; -} - - -uint Material::hash() { - return qHash(name); -} - - -bool Material::hasTransparency() const { - return float(color_diffuse.alphaF()) * (1.f - transparency) < 1.f; -} - - -bool Material::isMapsChanged() const { - return map_diffuse ._changed || - map_normal ._changed || - map_metalness._changed || - map_roughness._changed || - map_emission ._changed || - map_relief ._changed; -} - - -bool Material::isMapChanged(int type) const { - switch (type) { - case mtDiffuse : return map_diffuse ._changed; - case mtNormal : return map_normal ._changed; - case mtMetalness: return map_metalness._changed; - case mtRoughness: return map_roughness._changed; - case mtEmission : return map_emission ._changed; - case mtRelief : return map_relief ._changed; - } - return false; -} - - -void Material::load(TextureManager * tm) { - map_diffuse .load(tm); - map_normal .load(tm); - map_metalness.load(tm); - map_roughness.load(tm); - map_emission .load(tm); - map_relief .load(tm); -} - - -void Material::setMapsChanged() { - map_diffuse ._changed = true; - map_normal ._changed = true; - map_metalness._changed = true; - map_roughness._changed = true; - map_emission ._changed = true; - map_relief ._changed = true; -} - - -void Material::setTypes() { - map_diffuse ._type = mtDiffuse ; - map_normal ._type = mtNormal ; - map_metalness._type = mtMetalness; - map_roughness._type = mtRoughness; - map_emission ._type = mtEmission ; - map_relief ._type = mtRelief ; -} - - -void Material::detectMaps() { - map_diffuse .use_bitmap = !map_diffuse .bitmap_path.isEmpty(); - map_normal .use_bitmap = !map_normal .bitmap_path.isEmpty(); - map_metalness.use_bitmap = !map_metalness.bitmap_path.isEmpty(); - map_roughness.use_bitmap = !map_roughness.bitmap_path.isEmpty(); - map_emission .use_bitmap = !map_emission .bitmap_path.isEmpty(); - map_relief .use_bitmap = !map_relief .bitmap_path.isEmpty(); -} diff --git a/qglengine/core/glmaterial.h b/qglengine/core/glmaterial.h deleted file mode 100644 index 661d3dc..0000000 --- a/qglengine/core/glmaterial.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - QGL Material - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLMATERIAL_H -#define GLMATERIAL_H - -#include "glshaders_types.h" -#include "chunkstream.h" - - -class Map { -public: - Map(); - void setBitmapPath(const QString & p); - void clearBitmap() {setBitmapPath(QString());} - bool hasBitmap() const {return !bitmap_path.isEmpty();} - void load(TextureManager * tm); - void copyToQGLMap(QGLEngineShaders::QGLMap & m) const; - QString bitmap_path; - GLuint bitmap_id; - QPointF bitmap_offset; - QPointF bitmap_scale; - float color_amount; - float color_offset; - bool use_bitmap; - - bool _changed; - int _type, _layer; -}; - -class Material { -public: - Material(const QString _name = QString()); - uint hash(); - bool hasTransparency() const; - bool isMapsChanged() const; - bool isMapChanged(int type) const; - void load(TextureManager * tm); - void setMapsChanged(); - void setTypes(); - void detectMaps(); - QString name; - QColor color_diffuse; - QColor color_emission; - bool glass; - float transparency; - float reflectivity; - float iof; - float dispersion; - Map map_diffuse ; - Map map_normal ; - Map map_metalness; - Map map_roughness; - Map map_emission ; - Map map_relief ; - bool _changed; - int _index; - //GLCubeTexture map_reflection; -}; - - -inline QDataStream & operator <<(QDataStream & s, const Map & m) { - ChunkStream cs; - cs.add(1, m.bitmap_path).add(2, m.color_amount).add(3, m.color_offset).add(6, m.bitmap_scale) - .add(7, m.use_bitmap); - s << cs.data(); return s; -} -inline QDataStream & operator >>(QDataStream & s, Map & m) { - ChunkStream cs(s); - cs.readAll(); - cs.get(1, m.bitmap_path).get(2, m.color_amount).get(3, m.color_offset).get(6, m.bitmap_scale) - .get(7, m.use_bitmap); - return s; -} - -inline QDataStream & operator <<(QDataStream & s, const Material * m) { - ChunkStream cs; - cs.add(1, m->name).add(2, m->color_diffuse).add(4, m->color_emission) - .add(5, m->transparency).add(6, m->reflectivity).add(7, m->glass).add(8, m->map_diffuse).add(9, m->map_normal) - .add(10, m->map_relief).add(11, m->map_metalness).add(12, m->map_roughness).add(13, m->map_emission); - s << /*qCompress*/(cs.data()); return s; -} -inline QDataStream & operator >>(QDataStream & s, Material *& m) { - m = new Material(); - //QByteArray ba; - //s >> ba; - //ba = qUncompres(ba); - ChunkStream cs(s); - while (!cs.atEnd()) { - switch (cs.read()) { - case 1: cs.get(m->name); break; - case 2: cs.get(m->color_diffuse); break; - case 4: cs.get(m->color_emission); break; - case 5: cs.get(m->transparency); break; - case 6: cs.get(m->reflectivity); break; - case 7: cs.get(m->glass); break; - case 8: cs.get(m->map_diffuse); break; - case 9: cs.get(m->map_normal); break; - case 10: cs.get(m->map_relief); break; - case 11: cs.get(m->map_metalness); break; - case 12: cs.get(m->map_roughness); break; - case 13: cs.get(m->map_emission); break; - } - } - m->setTypes(); - return s; -} - -#endif // GLMATERIAL_H diff --git a/qglengine/core/glmesh.cpp b/qglengine/core/glmesh.cpp deleted file mode 100644 index 1b2079d..0000000 --- a/qglengine/core/glmesh.cpp +++ /dev/null @@ -1,426 +0,0 @@ -/* - QGL Mesh - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#define GL_GLEXT_PROTOTYPES -#include -#include "glmesh.h" -#include "globject.h" -#include - -using namespace QGLEngineShaders; - -//static int _count = 0; - -Mesh::Mesh(GLenum geom_type_): geom_type(geom_type_), - buffer_geom(GL_ARRAY_BUFFER, GL_STATIC_DRAW), - buffer_ind (GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW) { - hash_ = 0; - changed = hash_changed = true; - //qDebug() << "Mesh, now" << ++_count; -} - - -Mesh::~Mesh() { - //qDebug() << "~Mesh, now" << --_count; - //destroy(); -} - - -Mesh * Mesh::clone() { - Mesh * c = new Mesh(); - c->vertices_ = vertices_ ; - c->normals_ = normals_ ; - c->texcoords_ = texcoords_; - c->triangles_ = triangles_; - c->lines_ = lines_; - c->geom_type = geom_type; - c->hash_ = hash_; - c->hash_changed = hash_changed; - //qDebug() << "clone VBO"; - return c; -} - - -void Mesh::init(QOpenGLExtraFunctions * f) { - if (!isInit()) { - buffer_geom.init(f); - buffer_ind .init(f); - changed = true; - } -} - - -void Mesh::destroy(QOpenGLExtraFunctions * f) { - buffer_geom.destroy(f); - buffer_ind .destroy(f); - QList vaol = vao_map.values(); - foreach (VertexObject* vao, vaol) - vao->destroy(f); - qDeleteAll(vao_map); - vao_map.clear(); -} - - -void Mesh::calculateNormals() { - normals_.resize(vertices_.size()); - QVector3D dv1, dv2, n; - foreach (const Vector3i & t, triangles_) { - QVector3D & v0(vertices_[t.p0]); - QVector3D & v1(vertices_[t.p1]); - QVector3D & v2(vertices_[t.p2]); - dv1 = v1 - v0, dv2 = v2 - v0; - n = QVector3D::crossProduct(dv1, dv2).normalized(); - normals_[t.p0] = n; - normals_[t.p1] = n; - normals_[t.p2] = n; - } -} - - -void Mesh::calculateTangents() { - if (vertices_.isEmpty() || texcoords_.isEmpty()) return; - if (texcoords_.size() != vertices_.size()) return; - tangents_ .resize(vertices_.size()); - bitangents_.resize(vertices_.size()); - //qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "..."; - QVector3D dv1, dv2; - QVector2D dt1, dt2; - QVector3D tan, bitan; - foreach (const Vector3i & t, triangles_) { - QVector3D & v0(vertices_ [t.p0]); - QVector3D & v1(vertices_ [t.p1]); - QVector3D & v2(vertices_ [t.p2]); - QVector2D & t0(texcoords_[t.p0]); - QVector2D & t1(texcoords_[t.p1]); - QVector2D & t2(texcoords_[t.p2]); - dv1 = v1 - v0, dv2 = v2 - v0; - dt1 = t1 - t0, dt2 = t2 - t0; - tan = (dv1 * dt2.y() - dv2 * dt1.y()).normalized(); - bitan = (dv2 * dt1.x() - dv1 * dt2.x()).normalized(); - tangents_ [t.p0] = tan; - tangents_ [t.p1] = tan; - tangents_ [t.p2] = tan; - bitangents_[t.p0] = bitan; - bitangents_[t.p1] = bitan; - bitangents_[t.p2] = bitan; - //qDebug() << " t" << t << vi << ti << dv1.toQVector3D() << "..."; - } - //qDebug() << "calculateBinormals" << vcnt << tcnt << tangents_.size(); -} - - -VertexObject * Mesh::vaoByType(int type) { - VertexObject *& vao(vao_map[type]); - if (!vao) { - vao = new VertexObject(); - } - return vao; -} - - -bool Mesh::rebuffer(QOpenGLExtraFunctions * f) { - changed = false; - if (vertices_.isEmpty()) return true; - if (normals_.isEmpty()) - calculateNormals(); - calculateTangents(); - vert_count = qMin(vertices_.size(), normals_.size()); - vert_count = qMin(vert_count, tangents_.size()); - vert_count = qMin(vert_count, bitangents_.size()); - vert_count = qMin(vert_count, texcoords_.size()); - data_.resize(vert_count); - for (int i = 0; i < vert_count; ++i) { - Vertex & v(data_[i]); - v.pos = vertices_ [i]; - v.normal = normals_ [i]; - v.tangent = tangents_ [i]; - v.bitangent = bitangents_[i]; - v.tex = texcoords_ [i]; - } - int gsize = data_.size() * sizeof(Vertex); - int tsize = triangles_.size() * sizeof(Vector3i); - int lsize = lines_.size() * sizeof(Vector2i); - - buffer_geom.bind(f); - buffer_geom.resize(f, gsize); - buffer_geom.load(f, data_.constData(), gsize); - - buffer_ind.bind(f); - if (geom_type == GL_TRIANGLES) { - buffer_ind.resize(f, tsize); - buffer_ind.load(f, triangles_.constData(), tsize); - } else { - buffer_ind.resize(f, lsize); - buffer_ind.load(f, lines_.constData(), lsize); - } - - return !isEmpty(); -} - - -void Mesh::draw(QOpenGLExtraFunctions * f, int count, int type) { - if (isEmpty()) return; - if (!isInit()) init(f); - if (changed) rebuffer(f); - //qDebug() << "draw" << geom_type << vert_count << count; - - VertexObject * vao = vaoByType(type); - vao->bindBuffers(f, buffer_geom, buffer_ind); - if (geom_type == GL_TRIANGLES) - vao->draw(f, geom_type, triangles_.size() * 3, count); - else - vao->draw(f, geom_type, lines_.size() * 2, count); -} - - -void Mesh::clear() { - vertices_ .clear(); - normals_ .clear(); - tangents_ .clear(); - bitangents_.clear(); - texcoords_ .clear(); - triangles_ .clear(); - lines_ .clear(); - data_ .clear(); - changed = hash_changed = true; -} - - -void Mesh::loadObject(QOpenGLExtraFunctions * f, const Object & object, int type) { - VertexObject * vao = vaoByType(type); - vao->loadObject(f, object); -} - - -void Mesh::loadObjects(QOpenGLExtraFunctions * f, const QVector & objects, int type) { - VertexObject * vao = vaoByType(type); - vao->loadObjects(f, objects); -} - - -void Mesh::loadSelections(QOpenGLExtraFunctions * f, const QVector & sels, int type) { - VertexObject * vao = vaoByType(type); - vao->loadSelections(f, sels); -} - - -uint Mesh::hash() const { - if (hash_changed) { - hash_changed = false; - hash_ = qHashBits(vertices_ .constData(), vertices_ .size() * sizeof(QVector3D)); - hash_ ^= qHashBits(normals_ .constData(), normals_ .size() * sizeof(QVector3D)); - hash_ ^= qHashBits(texcoords_.constData(), texcoords_.size() * sizeof(QVector2D)); - hash_ ^= qHashBits(triangles_.constData(), triangles_.size() * sizeof( Vector3i)); - hash_ ^= qHashBits(lines_ .constData(), lines_ .size() * sizeof( Vector2i)); - } - return hash_; -} - - -bool Mesh::isObjectsChanged(int type) const { - return (const_cast(this))->vaoByType(type)->isObjectsChanged(); -} - - -bool Mesh::isSelectionChanged(int type) const { - return (const_cast(this))->vaoByType(type)->isSelectionChanged(); -} - - -void Mesh::setObjectsChanged(int type, bool yes) { - vaoByType(type)->setObjectsChanged(yes); -} - - -void Mesh::setSelectionChanged(int type, bool yes) { - vaoByType(type)->setSelectionChanged(yes); -} - - -void Mesh::setAllObjectsChanged(bool yes) { - QMapIterator it(vao_map); - while (it.hasNext()) - it.next().value()->setObjectsChanged(yes); -} - - -void Mesh::setAllSelectionChanged(bool yes) { - QMapIterator it(vao_map); - while (it.hasNext()) - it.next().value()->setSelectionChanged(yes); -} - - -void Mesh::translatePoints(const QVector3D & dp) { - QMatrix4x4 m; - m.translate(dp); - transformPoints(m); -} - - -void Mesh::scalePoints(const QVector3D & dp) { - QMatrix4x4 m; - m.scale(dp); - transformPoints(m); -} - - -void Mesh::rotatePoints(const double & angle, const QVector3D & a) { - QMatrix4x4 m; - m.rotate(angle, a); - transformPoints(m); -} - - -void Mesh::transformPoints(const QMatrix4x4 & mat) { - if (vertices_.isEmpty()) return; - int vcnt = vertices_.size(), ncnt = normals_.size(); - for (int i = 0; i < vcnt; ++i) { - vertices_[i] = (mat * QVector4D(vertices_[i], 1)).toVector3D(); - if (i < ncnt) - normals_[i] = (mat * QVector4D(normals_[i], 0)).toVector3D(); - } - changed = hash_changed = true; -} - - -void Mesh::flipNormals() { - if (vertices_.isEmpty()) return; - for (int i = 0; i < triangles_.size(); ++i) - piSwap(triangles_[i].p1, triangles_[i].p2); - for (int i = 0; i < lines_.size(); ++i) - piSwap(lines_[i].p0, lines_[i].p1); - int ncnt = normals_.size(); - for (int i = 0; i < ncnt; ++i) - normals_[i] = -normals_[i]; - changed = hash_changed = true; -} - - -void Mesh::append(const Mesh * m) { - if (!m) return; - if (m->isEmpty()) return; - if (normals_.isEmpty()) calculateNormals(); - int vcnt = vertices_.size(); - vertices_ .append(m->vertices_ ); - normals_ .append(m->normals_ ); - texcoords_.append(m->texcoords_); - QVector tri = m->triangles_; - for (int i = 0; i < tri.size(); ++i) - tri[i] += vcnt; - triangles_.append(tri); - QVector lin = m->lines_; - for (int i = 0; i < lin.size(); ++i) - lin[i] += vcnt; - lines_.append(lin); -} - - -bool Mesh::saveToFile(const QString & filename) { - if (filename.isEmpty()) return false; - QFile f(filename); - QByteArray ba; - if (f.open(QFile::WriteOnly)) { - QDataStream out(&ba, QFile::WriteOnly); - out << vertices_ << normals_ << texcoords_ << triangles_ << lines_; - ba = qCompress(ba); - f.resize(0); - f.write(ba); - f.close(); - return true; - } - return false; -} - - -bool Mesh::loadFromFile(const QString & filename) { - if (filename.isEmpty()) return false; - QFile f(filename); - QByteArray ba; - if (f.open(QFile::ReadOnly)) { - ba = f.readAll(); - if (ba.isEmpty()) return false; - ba = qUncompress(ba); - QDataStream in(ba); - in >> vertices_ >> normals_ >> texcoords_ >> triangles_ >> lines_; - changed = hash_changed = true; - f.close(); - return !isEmpty(); - } - return false; -} - - -Box3D Mesh::boundingBox() const { - if (vertices_.isEmpty()) return Box3D(); - int vcnt = vertices_.size(); - //qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "..."; - GLfloat mix, miy, miz, max, may, maz; - QVector3D v0(vertices_[0]); - mix = max = v0.x(); - miy = may = v0.y(); - miz = maz = v0.z(); - Box3D bound; - for (int i = 1; i < vcnt; ++i) { - const QVector3D & v(vertices_[i]); - if (mix > v.x()) mix = v.x(); - if (max < v.x()) max = v.x(); - if (miy > v.y()) miy = v.y(); - if (may < v.y()) may = v.y(); - if (miz > v.z()) miz = v.z(); - if (maz < v.z()) maz = v.z(); - } - bound.x = mix; - bound.y = miy; - bound.z = miz; - bound.length = max - mix; - bound.width = may - miy; - bound.height = maz - miz; - return bound; -} - - -QDataStream & operator <<(QDataStream & s, const Mesh * m) { - ChunkStream cs; - //qDebug() << "place VBO" << m.vertices_.size() << m.normals_.size() << m.texcoords_.size() << m.colors_.size() << "..."; - cs.add(1, m->vertices_).add(2, m->normals_).add(3, m->texcoords_) - .add(6, m->triangles_).add(7, m->lines_).add(10, int(m->geom_type)); - //qDebug() << "place VBO done" << cs.data().size() << "..."; - s << /*qCompress*/(cs.data()); return s; -} - - -QDataStream & operator >>(QDataStream & s, Mesh *& m) { - m = new Mesh(); - //QByteArray ba; - //s >> ba; - //ba = qUncompress(ba); - ChunkStream cs(s); - while (!cs.atEnd()) { - switch (cs.read()) { - case 1 : cs.get(m->vertices_ ); break; - case 2 : cs.get(m->normals_ ); break; - case 3 : cs.get(m->texcoords_); break; - case 6 : cs.get(m->triangles_); break; - case 7 : cs.get(m->lines_ ); break; - case 10: m->geom_type = cs.getData(); break; - } - } - m->changed = true; - return s; -} diff --git a/qglengine/core/glmesh.h b/qglengine/core/glmesh.h deleted file mode 100644 index e87f336..0000000 --- a/qglengine/core/glmesh.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - QGL Mesh - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLMESH_H -#define GLMESH_H - -#include -#include "glvertexobject.h" - - -class Mesh -{ - friend class ObjectBase; - friend class Scene; - friend class Renderer; - friend QDataStream & operator <<(QDataStream & s, const Mesh * m); - friend QDataStream & operator >>(QDataStream & s, Mesh *& m); -public: - Mesh(GLenum geom_type_ = GL_TRIANGLES); - ~Mesh(); - - Mesh * clone(); - - //GLVBO & operator =(const GLVBO & o) {return *this;} - - void init (QOpenGLExtraFunctions * f); - void destroy (QOpenGLExtraFunctions * f); - bool rebuffer(QOpenGLExtraFunctions * f); - void draw (QOpenGLExtraFunctions * f, int count, int type = 0); - void clear(); - void loadObject (QOpenGLExtraFunctions * f, const QGLEngineShaders::Object & object, int type = 0); - void loadObjects (QOpenGLExtraFunctions * f, const QVector & objects, int type = 0); - void loadSelections(QOpenGLExtraFunctions * f, const QVector & sels, int type = 0); - - int verticesCount() const {return vertices_.size();} - int trianglesCount() const {return triangles_.size();} - int linesCount() const {return lines_.size();} - bool isInit() const {return buffer_geom.isInit();} - bool isEmpty() const {return vertices_.isEmpty();} - uint hash() const; - - bool isObjectsChanged (int type = 0) const; - bool isSelectionChanged (int type = 0) const; - void setObjectsChanged (int type = 0, bool yes = true); - void setSelectionChanged(int type = 0, bool yes = true); - void setAllObjectsChanged (bool yes = true); - void setAllSelectionChanged(bool yes = true); - - QVector & vertices () {changed = hash_changed = true; return vertices_;} - QVector & normals () {changed = hash_changed = true; return normals_;} - QVector & texcoords() {changed = hash_changed = true; return texcoords_;} - QVector< Vector3i> & indicesTriangles() {changed = hash_changed = true; return triangles_;} - QVector< Vector2i> & indicesLines () {changed = hash_changed = true; return lines_;} - - void translatePoints(const QVector3D & dp); - void translatePoints(const double & x, const double & y, const double & z) {translatePoints(QVector3D(x, y, z));} - void scalePoints (const QVector3D & dp); - void scalePoints (const double & s) {scalePoints(QVector3D(s, s, s));} - void rotatePoints (const double & angle, const QVector3D & a); - void rotatePoints (const double & angle, const double & x, const double & y, const double & z) {rotatePoints(angle, QVector3D(x, y, z));} - void transformPoints(const QMatrix4x4 & mat); - void flipNormals(); - void append(const Mesh * m); - - bool saveToFile(const QString & filename); - bool loadFromFile(const QString & filename); - - Box3D boundingBox() const; - -private: - void calculateNormals(); - void calculateTangents(); - VertexObject * vaoByType(int type); - - QVector vertices_, normals_, tangents_, bitangents_; - QVector texcoords_; - QVector< Vector3i> triangles_; - QVector< Vector2i> lines_; - - QVector data_; - GLenum geom_type; - Buffer buffer_geom, buffer_ind; - QMap vao_map; - mutable uint hash_; - mutable bool hash_changed; - int vert_count; - bool changed; - -}; - - -QDataStream & operator <<(QDataStream & s, const Mesh * m); -QDataStream & operator >>(QDataStream & s, Mesh *& m); - -#endif // GLMESH_H diff --git a/qglengine/core/glprimitives.cpp b/qglengine/core/glprimitives.cpp deleted file mode 100644 index 6f6579b..0000000 --- a/qglengine/core/glprimitives.cpp +++ /dev/null @@ -1,437 +0,0 @@ -/* - QGL Primitives - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "glprimitives.h" -#include "glmesh.h" - - -Mesh * Primitive::plane(float width, float length) { - Mesh * ret = new Mesh(); - QVector & v(ret->vertices ()); - QVector & n(ret->normals ()); - QVector & t(ret->texcoords()); - QVector< Vector3i> & i(ret->indicesTriangles ()); - float hw = width / 2.f, hl = length / 2.f; - for (int j = 0; j < 4; ++j) n << QVector3D(0., 0., 1.); - t << QVector2D(0., 0.) << QVector2D(0., 1.) << QVector2D(1., 1.) << QVector2D(1., 0.); - v << QVector3D(-hw, -hl, 0.) << QVector3D(-hw, hl, 0.) << QVector3D(hw, hl, 0.) << QVector3D(hw, -hl, 0.); - i << Vector3i(0, 2, 1) << Vector3i(0, 3, 2); - return ret; -} - - -Mesh * Primitive::cube(float width, float length, float height) { - Mesh * ret = new Mesh(); - QVector3D scale(width, length, height); - QVector & v(ret->vertices ()); - QVector & n(ret->normals ()); - QVector & t(ret->texcoords()); - QVector< Vector3i> & i(ret->indicesTriangles ()); - float hs = 0.5f; - int si = 0; - QMatrix4x4 mat; - - si = v.size(); - for (int j = 0; j < 4; ++j) n << QVector3D(0., -1., 0.); - t << QVector2D(0., 0.) << QVector2D(1., 0.) << QVector2D(1., 1.) << QVector2D(0., 1.); - v << QVector3D(-hs, -hs, -hs) << QVector3D(hs, -hs, -hs) << QVector3D(hs, -hs, hs) << QVector3D(-hs, -hs, hs); - i << Vector3i(si + 0, si + 1, si + 2) << Vector3i(si + 0, si + 2, si + 3); - - for (int r = 0; r < 3; ++r) { - si = v.size(); - mat.rotate(90., 0., 0., 1.); - QVector3D cn = mat.map(n[0]); - for (int j = 0; j < 4; ++j) { - n << cn; - v << mat.map(QVector4D(v[j])).toVector3D(); - } - t << QVector2D(0., 0.) << QVector2D(1., 0.) << QVector2D(1., 1.) << QVector2D(0., 1.); - i << Vector3i(si + 0, si + 1, si + 2) << Vector3i(si + 0, si + 2, si + 3); - } - - mat.setToIdentity(); - mat.rotate(90., 1., 0.,0.); - for (int r = 0; r < 2; ++r) { - si = v.size(); - mat.rotate(180., 1., 0.,0.); - QVector3D cn = mat.map(n[0]); - for (int j = 0; j < 4; ++j) { - n << cn; - v << mat.map(QVector4D(v[j])).toVector3D(); - } - t << QVector2D(0., 0.) << QVector2D(1., 0.) << QVector2D(1., 1.) << QVector2D(0., 1.); - i << Vector3i(si + 0, si + 1, si + 2) << Vector3i(si + 0, si + 2, si + 3); - } - - for (int i = 0; i < v.size(); ++i) - v[i] *= scale; - - return ret; -} - - -Mesh * Primitive::ellipsoid(int segments_wl, int segments_h, float radius, float end_angle) { - Mesh * ret = new Mesh(); - QVector & v(ret->vertices ()); - QVector & n(ret->normals ()); - QVector & t(ret->texcoords()); - QVector< Vector3i> & ind(ret->indicesTriangles()); - int hseg = segments_h + 1, wlseg = segments_wl + 1; - double crw, crl, a, ch, twl; - double eang = deg2rad * end_angle; - - QVector3D cp; - for (int i = 0; i <= hseg; i++) { - ch = -cos((double)i / hseg * M_PI); - cp.setZ(ch * radius); - twl = sqrt(1. - ch * ch); - crw = twl * radius; - crl = twl * radius; - int cvcnt = wlseg * 2; - for (int j = 0; j < cvcnt; j++) { - a = (double)j / (cvcnt - 1) * eang; - cp.setX(crl * cos(a)); - cp.setY(crw * sin(a)); - v << cp; - t << QVector2D((double)j / (cvcnt - 1), ch/2.f + 0.5f); - n << cp.normalized(); - int si = v.size() - 1; - if (j > 0 && i > 0) { - ind << Vector3i(si - cvcnt - 1, si, si - 1); - ind << Vector3i(si - cvcnt, si, si - cvcnt - 1); - } - } - } - if (end_angle < 360.) { - Mesh * cap = Primitive::disc(segments_h+1, radius, 180); - cap->rotatePoints(90, 0, 1, 0); - cap->rotatePoints(-90, 0, 0, 1); - ret->append(cap); - cap->flipNormals(); - cap->rotatePoints(end_angle, 0, 0, 1); - ret->append(cap); - delete cap; - } - return ret; -} - - -Mesh * Primitive::disc(int segments, float radius, float end_angle) { - Mesh * ret = new Mesh(); - QVector & v(ret->vertices ()); - QVector & n(ret->normals ()); - QVector & t(ret->texcoords()); - QVector< Vector3i> & ind(ret->indicesTriangles()); - - segments = qMax(segments + 1, 4); - QVector3D cp; - v << QVector3D(); - n << QVector3D(0, 0, 1); - t << QVector2D(0.5f, 0.5f); - end_angle *= deg2rad; - for (int i = 0; i < segments; i++) { - double a = (double)i / (segments - 1) * end_angle; - cp.setX(radius * cos(a)); - cp.setY(radius * sin(a)); - v << cp; - n << QVector3D(0, 0, 1); - t << QVector2D(cp.x() / radius + 1, cp.y() / radius + 1); - int si = v.size() - 1; - if (i > 0) ind << Vector3i(si - 1, si, 0); - } - return ret; -} - - -QVector3D coneNormal(double r, double height, double ang) { - QVector3D norm; - norm.setX(r * cos(ang)); - norm.setY(r * sin(ang)); - norm.setZ(0.); - double rl = norm.length(); - double ca = atan2(rl, height); - norm *= cos(ca); - norm.setZ(norm.length() * tan(ca)); - return norm.normalized(); -} - - -Mesh * Primitive::cone(int segments, float radius, float height) { - Mesh * ret = new Mesh(); - QVector & v(ret->vertices ()); - QVector & n(ret->normals ()); - QVector & t(ret->texcoords()); - QVector< Vector3i> & ind(ret->indicesTriangles()); - - int seg = qMax(segments + 1, 4); - QVector3D cp; - for (int i = 0; i < seg; i++) { - double a = (double)i / (seg - 1) * M_2PI; - cp.setX(radius * cos(a)); - cp.setY(radius * sin(a)); - if (i > 0) { - v << QVector3D(0, 0, height); - t << QVector2D((double)(i - 1) / (seg - 1), 1.f); - double ta = ((double)i - 0.5) / (seg - 1) * M_2PI; - n << coneNormal(radius, height, ta); - } - v << cp; - t << QVector2D((double)i / (seg - 1), 0.f); - n << coneNormal(radius, height, a); - int si = v.size() - 1; - if (i > 0) - ind << Vector3i(si - 1, si - 2, si); - } - - Mesh * cap = Primitive::disc(segments, radius); - cap->flipNormals(); - ret->append(cap); - delete cap; - - return ret; -} - - -Mesh * Primitive::cylinder(int segments, float radius, float height, float end_angle) { - Mesh * ret = new Mesh(); - QVector & v(ret->vertices ()); - QVector & n(ret->normals ()); - QVector & t(ret->texcoords()); - QVector< Vector3i> & ind(ret->indicesTriangles()); - - int seg = qMax(segments + 1, 4); - QVector3D cp, norm; - double eang = deg2rad * end_angle; - - for (int i = 0; i < seg; i++) { - double a = (double)i / (seg - 1) * eang; - cp.setX(radius * cos(a)); - cp.setY(radius * sin(a)); - cp.setZ(0.); - norm = cp.normalized(); - v << cp; - cp.setZ(height); - v << cp; - t << QVector2D((double)i / (seg - 1), 0.f); - t << QVector2D((double)i / (seg - 1), 1.f); - n << norm; n << norm; - int si = v.size() - 1; - if (i > 0) { - ind << Vector3i(si - 2, si - 1, si); - ind << Vector3i(si - 1, si - 2, si - 3); - } - } - - Mesh * cap = Primitive::disc(segments, radius, end_angle); - cap->flipNormals(); - ret->append(cap); - cap->translatePoints(QVector3D(0., 0., height)); - cap->flipNormals(); - ret->append(cap); - delete cap; - - if (end_angle < 360.) { - Mesh * cap = Primitive::plane(radius, height); - cap->rotatePoints(90, 1, 0, 0); - //cap->rotatePoints(-90, 0, 0, 1); - cap->translatePoints(radius/2, 0, height/2); - ret->append(cap); - cap->flipNormals(); - cap->rotatePoints(end_angle, 0, 0, 1); - ret->append(cap); - delete cap; - } - - return ret; -} - - -Mesh * Primitive::arrow(int segments, float thick, float angle) { - double cone_r = 1.5 * thick; - double cone_h = 2. * cone_r / tan(angle * deg2rad); - Mesh * ret = new Mesh(); - Mesh * m = Primitive::cylinder(segments, thick / 2., 1. - cone_h); - ret->append(m); - delete m; - m = Primitive::cone(segments, cone_r, cone_h); - m->translatePoints(QVector3D(0., 0., 1. - cone_h)); - ret->append(m); - delete m; - return ret; -} - - -Mesh * Primitive::torus(int segments_main, int segments_second, float radius_main, float radius_second, float end_angle) { - Mesh * ret = new Mesh(); - QVector & v(ret->vertices ()); - QVector & n(ret->normals ()); - QVector & t(ret->texcoords()); - QVector< Vector3i> & ind(ret->indicesTriangles()); - - QVector cv, cn; - QVector ct; - segments_second = qMax(segments_second + 1, 4); - for (int i = 0; i < segments_second; i++) { - double x = (double)i / (segments_second - 1); - double a = x * M_2PI; - cv << QVector3D(radius_second * cos(a), 0., radius_second * sin(a)); - cn << cv.back().normalized(); - ct << QVector2D(0., x); - cv.back() += QVector3D(radius_main, 0., 0.); - } - - segments_main = qMax(segments_main + 1, 4); - int ccnt = cv.size(), pcnt = 0; - for (int i = 0; i < segments_main; i++) { - double x = (double)i / (segments_main - 1); - QMatrix4x4 rm; - rm.rotate(x * end_angle, 0., 0., 1.); - for (int j = 0; j < ccnt; j++) { - ct[j].setX(x); - v << rm.map(cv[j]); - n << rm.map(cn[j]); - } - t.append(ct); - if (i > 0) { - for (int j = 0; j < ccnt - 1; j++) { - ind << Vector3i(pcnt + j, pcnt + j + 1, pcnt + j - ccnt); - ind << Vector3i(pcnt + j + 1, pcnt + j + 1 - ccnt, pcnt + j - ccnt); - } - } - pcnt = v.size(); - } - if (end_angle < 360.) { - Mesh * cap = Primitive::disc(segments_second-1, radius_second); - cap->rotatePoints(90, 1, 0, 0); - cap->translatePoints(radius_main, 0, 0); - ret->append(cap); - cap->flipNormals(); - cap->rotatePoints(end_angle, 0, 0, 1); - ret->append(cap); - delete cap; - } - return ret; -} - - - - -Mesh * Primitive::cubeFrame(float width, float length, float height) { - Mesh * ret = new Mesh(GL_LINES); - QVector3D scale(width, length, height); - QVector & v(ret->vertices ()); - QVector & n(ret->normals ()); - QVector & t(ret->texcoords()); - QVector< Vector2i> & i(ret->indicesLines()); - float hs = 0.5f; - v << QVector3D(-hs, -hs, -hs) << QVector3D(-hs, hs, -hs) << QVector3D( hs, hs, -hs) << QVector3D( hs, -hs, -hs); - v << QVector3D(-hs, -hs, hs) << QVector3D(-hs, hs, hs) << QVector3D( hs, hs, hs) << QVector3D( hs, -hs, hs); - for (int j = 0; j < 8; ++j) { - v[j] *= scale; - t << QVector2D(0, 0); - n << QVector3D(0,0,1); - } - for (int j = 0; j < 4; ++j) { - i << Vector2i(j, (j + 1) % 4); - i << Vector2i(j, j + 4); - i << Vector2i(j + 4, (j + 1) % 4 + 4); - } - return ret; -} - - -Mesh * Primitive::ellipsoidFrame(int segments_wl, int segments_h, float radius) { - Mesh * ret = new Mesh(GL_LINES); - QVector & v(ret->vertices ()); - QVector & n(ret->normals ()); - QVector & t(ret->texcoords()); - QVector< Vector2i> & ind(ret->indicesLines()); - int hseg = segments_h + 1, wlseg = segments_wl + 1; - double crw, crl, a, ch, twl; - - QVector3D cp; - for (int i = 0; i <= hseg; i++) { - ch = -cos((double)i / hseg * M_PI); - cp.setZ(ch * radius); - twl = sqrt(1. - ch * ch); - crw = twl * radius; - crl = twl * radius; - int cvcnt = wlseg * 2; - for (int j = 0; j < cvcnt; j++) { - a = (double)j / (cvcnt - 1) * M_2PI; - cp.setX(crl * cos(a)); - cp.setY(crw * sin(a)); - v << cp; - t << QVector2D((double)j / (cvcnt - 1), ch/2.f + 0.5f); - n << cp.normalized(); - int si = v.size() - 1; - if (j > 0 && i > 0) { - ind << Vector2i(si, si - 1); - ind << Vector2i(si - cvcnt, si); - } - } - } - return ret; -} - - -Mesh * Primitive::coneFrame(int segments, float radius, float height) { - Mesh * ret = new Mesh(GL_LINES); - QVector & v(ret->vertices ()); - QVector & n(ret->normals ()); - QVector & t(ret->texcoords()); - QVector< Vector2i> & ind(ret->indicesLines()); - - int seg = qMax(segments + 1, 4); - QVector3D cp; - for (int i = 0; i < seg; i++) { - double a = (double)i / (seg - 1) * M_2PI; - cp.setX(radius * cos(a)); - cp.setY(radius * sin(a)); - if (i > 0) { - v << QVector3D(0, 0, height); - t << QVector2D((double)(i - 1) / (seg - 1), 1.f); - double ta = ((double)i - 0.5) / (seg - 1) * M_2PI; - n << coneNormal(radius, height, ta); - } - v << cp; - t << QVector2D((double)i / (seg - 1), 0.f); - n << coneNormal(radius, height, a); - int si = v.size() - 1; - if (i > 0) { - ind << Vector2i(si - 1, si); - ind << Vector2i(si - 2, si); - } - } - - return ret; -} - - -Mesh * Primitive::lineFrame(QVector3D p0, QVector3D p1) { - Mesh * ret = new Mesh(GL_LINES); - QVector & v(ret->vertices ()); - QVector & n(ret->normals ()); - QVector & t(ret->texcoords()); - QVector< Vector2i> & ind(ret->indicesLines()); - v << p0 << p1; - n << QVector3D(0,0,1) << QVector3D(0,0,1); - t << QVector2D(0,0) << QVector2D(1,0); - ind << Vector2i(0, 1); - return ret; -} diff --git a/qglengine/core/glprimitives.h b/qglengine/core/glprimitives.h deleted file mode 100644 index 7129bb1..0000000 --- a/qglengine/core/glprimitives.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - QGL Primitives - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLPRIMITIVE_CUBE_H -#define GLPRIMITIVE_CUBE_H - -#include "gltypes.h" - - -namespace Primitive { - - -Mesh * plane(float width = 1., float length = 1.); - -Mesh * cube(float width = 1., float length = 1., float height = 1.); - -Mesh * ellipsoid(int segments_wl, int segments_h, float radius = 1., float end_angle = 360.); - -Mesh * disc(int segments, float radius = 1., float end_angle = 360.); - -Mesh * cone(int segments, float radius = 1., float height = 1.); - -Mesh * cylinder(int segments, float radius = 1., float height = 1., float end_angle = 360.); - -Mesh * arrow(int segments = 16, float thick = 0.04, float angle = 30.); // length = 1 - -Mesh * torus(int segments_main = 30, int segments_second = 16, float radius_main = 2.5, float radius_second = 0.5, float end_angle = 360.); - - -Mesh * lineFrame(QVector3D p0, QVector3D p1); - -Mesh * cubeFrame(float width = 1., float length = 1., float height = 1.); - -Mesh * ellipsoidFrame(int segments_wl, int segments_h, float radius = 1.); - -Mesh * coneFrame(int segments, float radius = 1., float height = 1.); - -} - -/* -class GLPrimitivePoint: public GLObjectBase -{ -public: - GLPrimitivePoint(double size = 1., QVector3D pos = QVector3D()) {sz = 8.;} - virtual void draw(QOpenGLShaderProgram * prog, bool simplest = false); -private: - double sz; -}; - - - - -class GLPrimitiveLine: public GLObjectBase -{ -public: - GLPrimitiveLine(QVector3D p0_ = QVector3D(), QVector3D p1_ = QVector3D()) {p0 = p0_; p1 = p1_;} - virtual void draw(QOpenGLShaderProgram * prog, bool simplest = false); - QVector3D point0() const {return p0;} - QVector3D point1() const {return p1;} - void setPoint0(const QVector3D & p) {p0 = p;} - void setPoint1(const QVector3D & p) {p1 = p;} -private: - QVector3D p0, p1; -}; - - - - -class GLPrimitiveEllipsoid: public GLObjectBase -{ -public: - GLPrimitiveEllipsoid(float width = 1., float length = 1., float height = 1., int seg_wl = 10, int seg_h = 10, QVector3D pos = QVector3D()); - virtual void init(); -private: - void putTriangle(const QVector3D & v0, const QVector3D & v1, const QVector3D & v2); - float w, l, h; - int swl, sh; -}; - - -class GLPrimitiveAxis: public GLObjectBase -{ -public: - GLPrimitiveAxis() {accept_fog = accept_light = cast_shadow = rec_shadow = select_ = false;} - virtual void draw(QOpenGLShaderProgram * prog, bool simplest = false); -}; -*/ - -#endif // GLPRIMITIVE_CUBE_H diff --git a/qglengine/core/glshaders.cpp b/qglengine/core/glshaders.cpp deleted file mode 100644 index 4fff0d2..0000000 --- a/qglengine/core/glshaders.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - QGLEngineShaders - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "gltypes.h" -#include "qglview.h" -#include "glshaders.h" -#include "glshaders_headers.h" - -using namespace QGLEngineShaders; - - -bool addShader(QOpenGLShaderProgram * prog, QOpenGLShader::ShaderType type, QString & content, const QString & file, bool add_qgl, const QString & defs) { - if (type == 0 || content.isEmpty()) { - content.clear(); - return true; - } - //qDebug() << "[QGLEngine] Shader" << file << "found" << (QOpenGLShader::ShaderTypeBit)(int)type << "section ..."; - if (add_qgl) { - switch (type) { - case QOpenGLShader::Fragment: - content.prepend(qgl_fragment_head); - content.prepend(qgl_uniform); - content.prepend(qgl_structs); - break; - case QOpenGLShader::Vertex : - content.prepend(qgl_vertex_head ); - break; - case QOpenGLShader::Geometry: - content.prepend(qgl_geometry_head); - break; - } - } - content.prepend(defs); - content.prepend(qgl_common_head); - bool ret = prog->addShaderFromSourceCode(type, content.toLatin1()); - if (!ret) qDebug() << "[QGLEngine] Shader" << file << "Compile error:\n" << prog->log(); - content.clear(); - return ret; -} - - -QString prepareDefines(const QStringList & defines) { - if (defines.isEmpty()) return QString(); - QString ret; - foreach (QString s, defines) - ret.append("#define " + s + "\n"); - return ret; -} - - -bool QGLEngineShaders::loadShadersMulti(QOpenGLShaderProgram *& prog, const QString & file, bool add_qgl, const QStringList & defines) { - if (!prog) - prog = new QOpenGLShaderProgram(); - prog->removeAllShaders(); - QFile f(file); - if (!f.open(QIODevice::ReadOnly)) { - qDebug() << "[QGLEngine] Shader" << file << "Error: can`t open file!"; - return false; - } - QTextStream ts(&f); - QString cur_shader, line, pl, defs = prepareDefines(defines); - QOpenGLShader::ShaderType type = 0; - while (!ts.atEnd()) { - line = ts.readLine(); - pl = line.trimmed().remove(' ').remove('\t').mid(2).toLower(); - pl.chop(2); - if (pl == "vertex" || pl == "vert") { - if (!addShader(prog, type, cur_shader, file, add_qgl, defs)) return false; - type = QOpenGLShader::Vertex; - continue; - } - if (pl == "fragment" || pl == "frag") { - if (!addShader(prog, type, cur_shader, file, add_qgl, defs)) return false; - type = QOpenGLShader::Fragment; - continue; - } - if (pl == "geometry" || pl == "geom") { - if (!addShader(prog, type, cur_shader, file, add_qgl, defs)) return false; - type = QOpenGLShader::Geometry; - continue; - } - if (pl == "tessellation_control") { - if (!addShader(prog, type, cur_shader, file, add_qgl, defs)) return false; - type = QOpenGLShader::TessellationControl; - continue; - } - if (pl == "tessellation_evaluation") { - if (!addShader(prog, type, cur_shader, file, add_qgl, defs)) return false; - type = QOpenGLShader::TessellationEvaluation; - continue; - } - cur_shader.append("\n"); - cur_shader.append(line); - } - if (!addShader(prog, type, cur_shader, file, add_qgl, defs)) return false; - if (!prog->link()) { - qDebug() << "[QGLEngine] Shader" << file << "Link error:\n" << prog->log(); - return false; - } - qDebug() << "[QGLEngine] Shader" << file << "ok"; - return true; -} - - -bool QGLEngineShaders::loadShaders(QOpenGLShaderProgram *& prog, const QStringList & files, bool add_qgl, const QStringList & defines) { - if (!prog) - prog = new QOpenGLShaderProgram(); - prog->removeAllShaders(); - QString cur_shader, defs = prepareDefines(defines); - foreach (QString f, files) { - QFileInfo fi(f); - QOpenGLShader::ShaderType type = 0; - if (fi.suffix().toLower() == "vert") type = QOpenGLShader::Vertex ; - if (fi.suffix().toLower() == "frag") type = QOpenGLShader::Fragment; - if (fi.suffix().toLower() == "geom") type = QOpenGLShader::Geometry; - if (type == 0) continue; - QFile file(f); - if (!file.open(QIODevice::ReadOnly)) { - qDebug() << "[QGLEngine] Shader" << f << "Error: can`t open file!"; - return false; - } - cur_shader = file.readAll(); - if (!addShader(prog, type, cur_shader, f, add_qgl, defs)) return false; - } - if (!prog->link()) { - qDebug() << "[QGLEngine] Shader" << files << "Link error:\n" << prog->log(); - return false; - } - qDebug() << "[QGLEngine] Shader" << files << "ok"; - return true; -} diff --git a/qglengine/core/glshaders.h b/qglengine/core/glshaders.h deleted file mode 100644 index 57fc6a9..0000000 --- a/qglengine/core/glshaders.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - QGLEngineShaders - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLSHADERS_H -#define GLSHADERS_H - -#include "gltypes.h" - -namespace QGLEngineShaders { - -bool loadShadersMulti(QOpenGLShaderProgram *& prog, const QString & file, bool add_qgl = true, const QStringList & defines = QStringList()); -bool loadShaders(QOpenGLShaderProgram *& prog, const QStringList & files, bool add_qgl = true, const QStringList & defines = QStringList()); - -} - -#endif // GLSHADERS_H diff --git a/qglengine/core/glshaders_headers.h b/qglengine/core/glshaders_headers.h deleted file mode 100644 index dac5c6e..0000000 --- a/qglengine/core/glshaders_headers.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - QGLEngineShaders - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLSHADERS_HEADERS_H -#define GLSHADERS_HEADERS_H - -namespace QGLEngineShaders { - -const int max_materials = 128; -const int max_lights = 256 ; - -const char qgl_common_head[] = - "#version 400 core\n" - ""; - -const char qgl_vertex_head[] = - "layout(location = 1 ) in vec3 qgl_Vertex ;\n" - "layout(location = 2 ) in vec3 qgl_Normal ;\n" - "layout(location = 3 ) in vec3 qgl_Tangent ;\n" - "layout(location = 4 ) in vec3 qgl_Bitangent ;\n" - "layout(location = 5 ) in vec2 qgl_Texture ;\n" - "layout(location = 6 ) in uint qgl_Material ;\n" - "layout(location = 7 ) in uint qgl_ObjectSelected;\n" - "layout(location = 8 ) in uint qgl_ObjectID ;\n" - "layout(location = 9 ) in vec4 qgl_ObjectColor ;\n" - "layout(location = 10) in mat4 qgl_ModelMatrix ;\n" - "out vec2 qgl_FragTexture;\n" - "flat out uint qgl_MaterialIndex;\n" - "uniform mat4 qgl_ViewMatrix;\n" - "uniform mat4 qgl_ViewProjMatrix;\n" - "mat3 qgl_getNormalMatrix() {return inverse(mat3(qgl_ViewMatrix * qgl_ModelMatrix));}\n" - "mat3 qgl_getTangentMatrix() {return mat3(qgl_ViewMatrix * qgl_ModelMatrix);}\n" - "vec4 qgl_ftransform() {return qgl_ViewProjMatrix * (qgl_ModelMatrix * vec4(qgl_Vertex, 1));}\n" - ""; - -const char qgl_fragment_head[] = - "in vec2 qgl_FragTexture;\n" - "flat in uint qgl_MaterialIndex;\n" - "out vec4 qgl_FragData[gl_MaxDrawBuffers];\n" - "vec4 qgl_materialTexture(uint type, vec2 coord, vec4 tex_shift) {\n" - " coord *= qgl_material[qgl_MaterialIndex].map[type].scale;\n" - " vec4 t = texture(qgl_texture_array[qgl_material[qgl_MaterialIndex].map[type].array_index],\n" - " vec3(coord, qgl_material[qgl_MaterialIndex].map[type].map_index));\n" - " t += tex_shift;\n" - " t.rgb = t.rgb * qgl_material[qgl_MaterialIndex].map[type].amount + qgl_material[qgl_MaterialIndex].map[type].offset;\n" - " return t;\n" - "}\n" - "#define qgl_FragColor qgl_FragData[0]\n" - ""; - -const char qgl_geometry_head[] = - ""; - -const char qgl_structs[] = - "#define QGL_MAPS_COUNT 6\n" - "#define QGL_MAP_DIFFUSE 0\n" - "#define QGL_MAP_NORMAL 1\n" - "#define QGL_MAP_METALNESS 2\n" - "#define QGL_MAP_ROUGHNESS 3\n" - "#define QGL_MAP_EMISSION 4\n" - "#define QGL_MAP_RELIEF 5\n" - "#define QGL_TEXTURE_ARRAY_EMPTY 0\n" - "#define QGL_TEXTURE_ARRAY_MAPS 1\n" - "struct QGLMap {\n" - " float offset;\n" - " float amount;\n" - " vec2 scale;\n" - " uint array_index;\n" - " uint map_index;\n" - "};\n" - "struct QGLMaterial {\n" - " vec4 color_diffuse;\n" - //" vec4 color_specular;\n" - " vec4 color_emission;\n" - " float transparency;\n" - " float reflectivity;\n" - " float iof;\n" - " float dispersion;\n" - " QGLMap map[QGL_MAPS_COUNT];\n" - "};\n" - "struct QGLLightParameter {\n" - " vec4 color;\n" - " vec4 decay_intensity;\n" - " vec4 angles;\n" - //" sampler2DShadow shadow;\n" - //" sampler2D shadowColor\n" - //" mat4 shadowMatrix;\n" - //" vec4 shadowDir0;\n" - //" vec4 shadowDir1;\n" - "};\n" - "struct QGLLightPosition {\n" - " vec4 position;\n" - " vec4 direction;\n" - "};\n" - ""; - -const char qgl_uniform[] = - "layout (std140) uniform QGLMaterialData {\n" - " QGLMaterial qgl_material[128];\n" - "};\n" - "layout (std140) uniform QGLLightParameterData {\n" - " QGLLightParameter qgl_light_parameter[256];\n" - "};\n" - "layout (std140) uniform QGLLightPositionData {\n" - " QGLLightPosition qgl_light_position[256];\n" - "};\n" - "uniform sampler2DArray qgl_texture_array[2];\n" - ""; - -} - -#endif // GLSHADERS_HEADERS_H diff --git a/qglengine/core/glshaders_types.cpp b/qglengine/core/glshaders_types.cpp deleted file mode 100644 index fe57b1b..0000000 --- a/qglengine/core/glshaders_types.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - QGLEngineShaders - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "glshaders_types.h" - - -QGLEngineShaders::QGLMap::QGLMap() { - offset = 0.; - amount = 1.; - scale = QVector2D(1., 1.); - array_index = map_index = 0; -} - - -QGLEngineShaders::QGLMaterial::QGLMaterial() { - color_diffuse = QVector4D(1., 1., 1., 0.); - color_emission = QVector4D(0., 0., 0., 0.); - transparency = 0.; - reflectivity = 0.; - iof = 0.; - dispersion = 0.; - map[mtNormal].map_index = emrBlue; - map[mtRoughness].amount = 0.75; - map[mtMetalness].amount = 0.25; -} - - -void QGLEngineShaders::prepareDrawGeom(QOpenGLExtraFunctions * f) { - //qDebug() << "prepareDrawGeom"; - - f->glEnableVertexAttribArray(pos_loc ); - f->glEnableVertexAttribArray(normal_loc ); - f->glEnableVertexAttribArray(tangent_loc ); - f->glEnableVertexAttribArray(bitangent_loc); - f->glEnableVertexAttribArray(tex_loc ); - - int size = sizeof(Vertex); - f->glVertexAttribPointer(pos_loc , 3, GL_FLOAT, GL_FALSE, size, (const void *)pos_offset ); - f->glVertexAttribPointer(normal_loc , 3, GL_FLOAT, GL_FALSE, size, (const void *)normal_offset ); - f->glVertexAttribPointer(tangent_loc , 3, GL_FLOAT, GL_FALSE, size, (const void *)tangent_offset ); - f->glVertexAttribPointer(bitangent_loc, 3, GL_FLOAT, GL_FALSE, size, (const void *)bitangent_offset); - f->glVertexAttribPointer(tex_loc , 2, GL_FLOAT, GL_FALSE, size, (const void *)tex_offset ); -} - - -void QGLEngineShaders::prepareDrawObj(QOpenGLExtraFunctions * f) { - //qDebug() << "prepareDrawObj"; - - f->glEnableVertexAttribArray(material_loc ); - f->glEnableVertexAttribArray(object_id_loc); - f->glEnableVertexAttribArray(color_loc ); - for (int i = 0; i < 4; ++i) { - f->glEnableVertexAttribArray(modelmatrix_loc + i); - } - - GLsizei size = sizeof(Object); - f->glVertexAttribIPointer(material_loc , 1, GL_UNSIGNED_INT , size, (const void *)material_offset ); - f->glVertexAttribIPointer(object_id_loc, 1, GL_UNSIGNED_INT , size, (const void *)object_id_offset); - f->glVertexAttribPointer (color_loc , 4, GL_FLOAT, GL_FALSE, size, (const void *)color_offset ); - for (int i = 0; i < 4; ++i) { - f->glVertexAttribPointer(modelmatrix_loc + i, 4, GL_FLOAT, GL_FALSE, size, (const void *)(modelmatrix_offset + sizeof(QVector4D)*i)); - } - - f->glVertexAttribDivisor(material_loc , 1); - f->glVertexAttribDivisor(object_id_loc, 1); - f->glVertexAttribDivisor(color_loc , 1); - for (int i = 0; i < 4; ++i) { - f->glVertexAttribDivisor(modelmatrix_loc + i, 1); - } - -} - - -void QGLEngineShaders::prepareDrawSel(QOpenGLExtraFunctions * f) { - //qDebug() << "prepareDrawObj"; - - f->glEnableVertexAttribArray(is_selected_loc); - GLsizei size = 1; - f->glVertexAttribIPointer(is_selected_loc, 1, GL_UNSIGNED_BYTE, size, (const void *)is_selected_offset); - f->glVertexAttribDivisor(is_selected_loc, 1); - -} diff --git a/qglengine/core/glshaders_types.h b/qglengine/core/glshaders_types.h deleted file mode 100644 index 55f44bc..0000000 --- a/qglengine/core/glshaders_types.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - QGLEngineShaders - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLSHADERS_TYPES_H -#define GLSHADERS_TYPES_H - -#include "gltypes.h" - -namespace QGLEngineShaders { - - -/// VBO - -// geometry -const GLsizei pos_offset = 0; -const GLsizei normal_offset = sizeof(QVector3D) + pos_offset ; -const GLsizei tangent_offset = sizeof(QVector3D) + normal_offset ; -const GLsizei bitangent_offset = sizeof(QVector3D) + tangent_offset ; -const GLsizei tex_offset = sizeof(QVector3D) + bitangent_offset; - -// object -const GLsizei material_offset = 0; -const GLsizei object_id_offset = sizeof(GLuint ) + material_offset ; -const GLsizei color_offset = sizeof(GLuint ) + object_id_offset ; -const GLsizei modelmatrix_offset = sizeof(QVector4D) + color_offset; - -const GLsizei is_selected_offset = 0; - -const GLuint pos_loc = 1 ; // qgl_Vertex -const GLuint normal_loc = 2 ; // qgl_Normal -const GLuint tangent_loc = 3 ; // qgl_Tangent -const GLuint bitangent_loc = 4 ; // qgl_Bitangent -const GLuint tex_loc = 5 ; // qgl_Texture - -const GLuint material_loc = 6 ; // qgl_Material -const GLuint object_id_loc = 8 ; // qgl_ObjectID -const GLuint color_loc = 9 ; // qgl_ObjectColor -const GLuint modelmatrix_loc = 10; // qgl_ModelViewProjectionMatrix - -const GLuint is_selected_loc = 7 ; // qgl_ObjectSelected - -#pragma pack(push, 1) -struct Vertex { - QVector3D pos; - QVector3D normal; - QVector3D tangent; - QVector3D bitangent; - QVector2D tex; -}; -struct Object { - Object() { - material = object_id = 0; - color = QVector4D(1,1,1,1); - QMatrix4x4().copyDataTo(modelmatrix); - } - GLuint material; - GLuint object_id; - QVector4D color; - GLfloat modelmatrix[16]; -}; -#pragma pack(pop) - - -/// UBO - -enum BindingPoints { - bpMaterials, - bpLightParameters, - bpLightPositions, -}; - -enum MapType { - mtDiffuse = 0, - mtNormal = 1, - mtMetalness = 2, - mtRoughness = 3, - mtEmission = 4, - mtRelief = 5, -}; -enum TextureArrayRole { - tarEmpty = 0, - tarMaps = 1, -}; -enum EmptyMapRole { - emrWhite = 0, - emrBlue = 1, -}; -#define QGL_MAPS_COUNT 6 -#pragma pack(push, 1) -struct QGLMap { - QGLMap(); - GLfloat offset; - GLfloat amount; - QVector2D scale; - GLuint array_index; - GLuint map_index; - GLfloat __res_2[2]; -}; -struct QGLMaterial { - QGLMaterial(); - QVector4D color_diffuse; - QVector4D color_emission; - GLfloat transparency; - GLfloat reflectivity; - GLfloat iof; - GLfloat dispersion; - QGLMap map[QGL_MAPS_COUNT]; -}; -struct QGLLightParameter { - QVector4D color; - QVector4D decay_intensity; // [^0, ^1, ^2, intensity] - QVector4D angles; // [start, cos(start), end, cos(end)] - //GLfloat shadow; - //GLfloat shadowMatrix[16]; -}; -struct QGLLightPosition { - QVector4D position; - QVector4D direction; -}; -#pragma pack(pop) - -void prepareDrawGeom(QOpenGLExtraFunctions * f); -void prepareDrawObj (QOpenGLExtraFunctions * f); -void prepareDrawSel (QOpenGLExtraFunctions * f); - - -} - -#endif // GLSHADERS_TYPES_H diff --git a/qglengine/core/gltexturearray.cpp b/qglengine/core/gltexturearray.cpp deleted file mode 100644 index 1149ad6..0000000 --- a/qglengine/core/gltexturearray.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - QGL Texture2DArray - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#define GL_GLEXT_PROTOTYPES -#include -#include "gltexturearray.h" - - -Texture2DArray::Texture2DArray(bool filter) { - target_ = GL_TEXTURE_2D_ARRAY; - texture_ = 0; - layers_ = 0; - filtering_ = filter; -} - - -Texture2DArray::~Texture2DArray() { -} - - -void Texture2DArray::init(QOpenGLExtraFunctions * f) { - if (!isInit()) { - f->glGenTextures(1, &texture_); - } -} - - -void Texture2DArray::destroy(QOpenGLExtraFunctions * f) { - if (texture_ != 0) { - f->glDeleteTextures(1, &texture_); - } - texture_ = 0; -} - - -void Texture2DArray::bind(QOpenGLExtraFunctions * f, int channel) { - f->glActiveTexture(GL_TEXTURE0 + channel); - f->glBindTexture(target_, texture_); -} - - -void Texture2DArray::release(QOpenGLExtraFunctions * f) { - f->glBindTexture(target_, 0); -} - - -bool Texture2DArray::resize(QOpenGLExtraFunctions * f, QSize new_size, int layers_count) { - if (new_size.isNull() || layers_count <= 0) return false; - if ((size_ == new_size) && (layers_ >= layers_count)) return false; - size_ = new_size; - layers_ = layers_count; - f->glBindTexture(target_, texture_); - f->glTexParameteri(target_, GL_TEXTURE_WRAP_S, GL_REPEAT); - f->glTexParameteri(target_, GL_TEXTURE_WRAP_T, GL_REPEAT); - if (filtering_) { - f->glTexParameteri(target_, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - f->glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - f->glTexParameteri(target_, GL_TEXTURE_MAX_ANISOTROPY_EXT, 8); - } else { - f->glTexParameteri(target_, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - f->glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - } - f->glTexImage3D(target_, 0, GL_RGBA8, size_.width(), size_.height(), layers_, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); - return true; -} - - -void Texture2DArray::load(QOpenGLExtraFunctions * f, const QImage & image, int layer) { - if (image.isNull() || size_.isNull() || layer < 0 || layer >= layers_) return; - QImage im = image.mirrored(false, true) - .scaled(size_, Qt::IgnoreAspectRatio, Qt::SmoothTransformation) - .convertToFormat(QImage::Format_RGBA8888); - //qDebug() << "Texture2DArray::load image" << image.size() << "to layer" << layer; - f->glTexSubImage3D(target_, 0, 0, 0, layer, size_.width(), size_.height(), 1, GL_RGBA, GL_UNSIGNED_BYTE, im.constBits()); -} - - -void Texture2DArray::mipmaps(QOpenGLExtraFunctions * f) { - f->glBindTexture(target_, texture_); - f->glGenerateMipmap(target_); -} diff --git a/qglengine/core/gltexturearray.h b/qglengine/core/gltexturearray.h deleted file mode 100644 index f8b32b7..0000000 --- a/qglengine/core/gltexturearray.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - QGL Texture2DArray - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLTEXTUREARRAY_H -#define GLTEXTUREARRAY_H - -#include "gltypes.h" - - -class Texture2DArray -{ - friend class ObjectBase; -public: - Texture2DArray(bool filter); - ~Texture2DArray(); - - void init (QOpenGLExtraFunctions * f); - void destroy (QOpenGLExtraFunctions * f); - - void bind (QOpenGLExtraFunctions * f, int channel = 0); - void release (QOpenGLExtraFunctions * f); - - // returns true if size changed - bool resize (QOpenGLExtraFunctions * f, QSize new_size, int layers_count); - void load (QOpenGLExtraFunctions * f, const QImage & image, int layer); - void mipmaps (QOpenGLExtraFunctions * f); - - GLuint ID() const {return texture_;} - bool isInit() const {return texture_ != 0;} - -private: - GLenum target_; - GLuint texture_; - QSize size_; - int layers_; - bool filtering_; - -}; - - -#endif // GLTEXTUREARRAY_H diff --git a/qglengine/core/gltransform.cpp b/qglengine/core/gltransform.cpp deleted file mode 100644 index d92ebb7..0000000 --- a/qglengine/core/gltransform.cpp +++ /dev/null @@ -1,441 +0,0 @@ -/* - QGL Transform - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - - -#include "gltransform.h" -#include "gltypes.h" -#include - - -inline void composeQMatrix4x4(const QVector3D & position, const QVector3D & orientation, const QVector3D & scale, QMatrix4x4 &m) { - const QMatrix3x3 rot3x3(Transform::toRotationMatrix(orientation)); - - // set up final matrix with scale, rotation and translation - m(0, 0) = scale.x() * rot3x3(0, 0); m(0, 1) = scale.y() * rot3x3(0, 1); m(0, 2) = scale.z() * rot3x3(0, 2); m(0, 3) = position.x(); - m(1, 0) = scale.x() * rot3x3(1, 0); m(1, 1) = scale.y() * rot3x3(1, 1); m(1, 2) = scale.z() * rot3x3(1, 2); m(1, 3) = position.y(); - m(2, 0) = scale.x() * rot3x3(2, 0); m(2, 1) = scale.y() * rot3x3(2, 1); m(2, 2) = scale.z() * rot3x3(2, 2); m(2, 3) = position.z(); - // no projection term - m(3, 0) = 0.0f; m(3, 1) = 0.0f; m(3, 2) = 0.0f; m(3, 3) = 1.0f; -} - -inline void decomposeQMatrix3x3(const QMatrix3x3 & m, QMatrix3x3 & Q, QVector3D & D, QVector3D & U) { - // Factor M = QR = QDU where Q is orthogonal, D is diagonal, - // and U is upper triangular with ones on its diagonal. - // Algorithm uses Gram-Schmidt orthogonalization (the QR algorithm). - // - // If M = [ m0 | m1 | m2 ] and Q = [ q0 | q1 | q2 ], then - // q0 = m0/|m0| - // q1 = (m1-(q0*m1)q0)/|m1-(q0*m1)q0| - // q2 = (m2-(q0*m2)q0-(q1*m2)q1)/|m2-(q0*m2)q0-(q1*m2)q1| - // - // where |V| indicates length of vector V and A*B indicates dot - // product of vectors A and B. The matrix R has entries - // - // r00 = q0*m0 r01 = q0*m1 r02 = q0*m2 - // r10 = 0 r11 = q1*m1 r12 = q1*m2 - // r20 = 0 r21 = 0 r22 = q2*m2 - // - // so D = diag(r00,r11,r22) and U has entries u01 = r01/r00, - // u02 = r02/r00, and u12 = r12/r11. - - // Q = rotation - // D = scaling - // U = shear - - // D stores the three diagonal entries r00, r11, r22 - // U stores the entries U[0] = u01, U[1] = u02, U[2] = u12 - - // build orthogonal matrix Q - float invLen = 1.0f / std::sqrt(m(0, 0) * m(0, 0) + m(1, 0) * m(1, 0) + m(2, 0) * m(2, 0)); - Q(0, 0) = m(0, 0) * invLen; - Q(1, 0) = m(1, 0) * invLen; - Q(2, 0) = m(2, 0) * invLen; - - float dot = Q(0, 0) * m(0, 1) + Q(1, 0) * m(1, 1) + Q(2, 0) * m(2, 1); - Q(0, 1) = m(0, 1) - dot * Q(0, 0); - Q(1, 1) = m(1, 1) - dot * Q(1, 0); - Q(2, 1) = m(2, 1) - dot * Q(2, 0); - invLen = 1.0f / std::sqrt(Q(0, 1) * Q(0, 1) + Q(1, 1) * Q(1, 1) + Q(2, 1) * Q(2, 1)); - Q(0, 1) *= invLen; - Q(1, 1) *= invLen; - Q(2, 1) *= invLen; - - dot = Q(0, 0) * m(0, 2) + Q(1, 0) * m(1, 2) + Q(2, 0) * m(2, 2); - Q(0, 2) = m(0, 2) - dot * Q(0, 0); - Q(1, 2) = m(1, 2) - dot * Q(1, 0); - Q(2, 2) = m(2, 2) - dot * Q(2, 0); - dot = Q(0, 1) * m(0, 2) + Q(1, 1) * m(1, 2) + Q(2, 1) * m(2, 2); - Q(0, 2) -= dot * Q(0, 1); - Q(1, 2) -= dot * Q(1, 1); - Q(2, 2) -= dot * Q(2, 1); - invLen = 1.0f / std::sqrt(Q(0, 2) * Q(0, 2) + Q(1, 2) * Q(1, 2) + Q(2, 2) * Q(2, 2)); - Q(0, 2) *= invLen; - Q(1, 2) *= invLen; - Q(2, 2) *= invLen; - - // guarantee that orthogonal matrix has determinant 1 (no reflections) - const float det = Q(0, 0) * Q(1, 1) * Q(2, 2) + Q(0, 1) * Q(1, 2) * Q(2, 0) + - Q(0, 2) * Q(1, 0) * Q(2, 1) - Q(0, 2) * Q(1, 1) * Q(2, 0) - - Q(0, 1) * Q(1, 0) * Q(2, 2) - Q(0, 0) * Q(1, 2) * Q(2, 1); - if (det < 0.0f) - Q *= -1.0f; - - // build "right" matrix R - QMatrix3x3 R(Qt::Uninitialized); - R(0, 0) = Q(0, 0) * m(0, 0) + Q(1, 0) * m(1, 0) + Q(2, 0) * m(2, 0); - R(0, 1) = Q(0, 0) * m(0, 1) + Q(1, 0) * m(1, 1) + Q(2, 0) * m(2, 1); - R(1, 1) = Q(0, 1) * m(0, 1) + Q(1, 1) * m(1, 1) + Q(2, 1) * m(2, 1); - R(0, 2) = Q(0, 0) * m(0, 2) + Q(1, 0) * m(1, 2) + Q(2, 0) * m(2, 2); - R(1, 2) = Q(0, 1) * m(0, 2) + Q(1, 1) * m(1, 2) + Q(2, 1) * m(2, 2); - R(2, 2) = Q(0, 2) * m(0, 2) + Q(1, 2) * m(1, 2) + Q(2, 2) * m(2, 2); - - // the scaling component - D[0] = R(0, 0); - D[1] = R(1, 1); - D[2] = R(2, 2); - - // the shear component - U[0] = R(0, 1) / D[0]; - U[1] = R(0, 2) / D[0]; - U[2] = R(1, 2) / D[1]; -} - -inline bool hasScale(const QMatrix4x4 &m) { - // If the columns are orthonormal and form a right-handed system, then there is no scale - float t(m.determinant()); - if (!qFuzzyIsNull(t - 1.0f)) - return true; - t = m(0, 0) * m(0, 0) + m(1, 0) * m(1, 0) + m(2, 0) * m(2, 0); - if (!qFuzzyIsNull(t - 1.0f)) - return true; - t = m(0, 1) * m(0, 1) + m(1, 1) * m(1, 1) + m(2, 1) * m(2, 1); - if (!qFuzzyIsNull(t - 1.0f)) - return true; - t = m(0, 2) * m(0, 2) + m(1, 2) * m(1, 2) + m(2, 2) * m(2, 2); - if (!qFuzzyIsNull(t - 1.0f)) - return true; - return false; -} - -inline void decomposeQMatrix4x4(const QMatrix4x4 & m, QVector3D & position, QVector3D & orientation, QVector3D & scale) { - Q_ASSERT(m.isAffine()); - - const QMatrix3x3 m3x3(m.toGenericMatrix<3, 3>()); - - QMatrix3x3 rot3x3(Qt::Uninitialized); - if (hasScale(m)) { - decomposeQMatrix3x3(m3x3, rot3x3, scale, position); - } else { - // we know there is no scaling part; no need for QDU decomposition - scale = QVector3D(1.0f, 1.0f, 1.0f); - rot3x3 = m3x3; - } - orientation = Transform::fromRotationMatrix(rot3x3); - position = QVector3D(m(0, 3), m(1, 3), m(2, 3)); -} - - - - -Transform::Transform(): m_scale(1.0f, 1.0f, 1.0f), - m_translation(), m_eulerRotationAngles(), m_matrixDirty(false) { -} - - -Transform & Transform::operator =(const Transform & t) { - m_scale = t.m_scale; - m_translation = t.m_translation; - m_eulerRotationAngles = t.m_eulerRotationAngles; - m_matrixDirty = true; - return *this; -} - - -void Transform::setMatrix(const QMatrix4x4 & m) { - if (m != matrix()) { - m_matrix = m; - m_matrixDirty = false; - QVector3D s; - QVector3D t; - QVector3D r; - decomposeQMatrix4x4(m, t, r, s); - m_scale = s; - m_translation = t; - m_eulerRotationAngles = r; - } -} - - -void Transform::setRotationX(float r) { - if (m_eulerRotationAngles.x() == r) - return; - m_eulerRotationAngles.setX(r); - m_matrixDirty = true; -} - - -void Transform::setRotationY(float r) { - if (m_eulerRotationAngles.y() == r) - return; - m_eulerRotationAngles.setY(r); - m_matrixDirty = true; -} - - -void Transform::setRotationZ(float r) { - if (m_eulerRotationAngles.z() == r) - return; - m_eulerRotationAngles.setZ(r); - m_matrixDirty = true; -} - - -QMatrix4x4 Transform::matrix() const { - buildMatrix(); - return m_matrix; -} - - -QMatrix4x4 Transform::matrixRotate() const { - buildMatrix(); - return m_matrixR; -} - - -QMatrix4x4 Transform::matrixScale() const { - buildMatrix(); - return m_matrixS; -} - - -QMatrix4x4 Transform::matrixRotateScale() const { - buildMatrix(); - return m_matrixWT; -} - - -QVector3D Transform::direction() const { - return matrixRotate().mapVector(QVector3D(0,0,-1)).normalized(); -} - - -void Transform::buildMatrix() const { - if (m_matrixDirty) { - composeQMatrix4x4(m_translation, m_eulerRotationAngles, m_scale, m_matrix); - composeQMatrix4x4(QVector3D(), m_eulerRotationAngles, m_scale, m_matrixWT); - composeQMatrix4x4(QVector3D(), m_eulerRotationAngles, QVector3D(1,1,1), m_matrixR); - composeQMatrix4x4(QVector3D(), QVector3D(), m_scale, m_matrixS); - m_matrixDirty = false; - } -} - - -float Transform::rotationX() const { - return m_eulerRotationAngles.x(); -} - - -float Transform::rotationY() const { - return m_eulerRotationAngles.y(); -} - - -float Transform::rotationZ() const { - return m_eulerRotationAngles.z(); -} - - -void Transform::setScale(const QVector3D & s) { - if (s != m_scale) { - m_scale = s; - m_matrixDirty = true; - } -} - - -void Transform::setScaleX(float s) { - if (s != m_scale.x()) { - m_scale.setX(s); - m_matrixDirty = true; - } -} - - -void Transform::setScaleY(float s) { - if (s != m_scale.y()) { - m_scale.setY(s); - m_matrixDirty = true; - } -} - - -void Transform::setScaleZ(float s) { - if (s != m_scale.z()) { - m_scale.setZ(s); - m_matrixDirty = true; - } -} - - -QVector3D Transform::scale3D() const { - return m_scale; -} - - -float Transform::scale() const { - return m_scale.x(); -} - - -void Transform::setRotation(const QVector3D & r) { - if (r != m_eulerRotationAngles) { - m_eulerRotationAngles = r; - m_matrixDirty = true; - } -} - - -QVector3D Transform::rotation() const { - return m_eulerRotationAngles; -} - - -void Transform::setTranslation(const QVector3D & t) { - if (t != m_translation) { - m_translation = t; - m_matrixDirty = true; - } -} - - -void Transform::setTranslationX(float t) { - if (t != m_translation.x()) { - m_translation.setX(t); - m_matrixDirty = true; - } -} - - -void Transform::setTranslationY(float t) { - if (t != m_translation.y()) { - m_translation.setY(t); - m_matrixDirty = true; - } -} - - -void Transform::setTranslationZ(float t) { - if (t != m_translation.z()) { - m_translation.setZ(t); - m_matrixDirty = true; - } -} - - -QVector3D Transform::translation() const { - return m_translation; -} - - -QQuaternion Transform::fromAxisAndAngle(const QVector3D & axis, float angle) { - return QQuaternion::fromAxisAndAngle(axis, angle); -} - - -QQuaternion Transform::fromAxisAndAngle(float x, float y, float z, float angle) { - return QQuaternion::fromAxisAndAngle(x, y, z, angle); -} - - -QQuaternion Transform::fromAxesAndAngles(const QVector3D & axis1, float angle1, - const QVector3D & axis2, float angle2) { - const QQuaternion q1 = QQuaternion::fromAxisAndAngle(axis1, angle1); - const QQuaternion q2 = QQuaternion::fromAxisAndAngle(axis2, angle2); - return q2 * q1; -} - - -QQuaternion Transform::fromAxesAndAngles(const QVector3D & axis1, float angle1, - const QVector3D & axis2, float angle2, - const QVector3D & axis3, float angle3) { - const QQuaternion q1 = QQuaternion::fromAxisAndAngle(axis1, angle1); - const QQuaternion q2 = QQuaternion::fromAxisAndAngle(axis2, angle2); - const QQuaternion q3 = QQuaternion::fromAxisAndAngle(axis3, angle3); - return q3 * q2 * q1; -} - - -QQuaternion Transform::fromAxes(const QVector3D & xAxis, const QVector3D & yAxis, const QVector3D & zAxis) { - return QQuaternion::fromAxes(xAxis, yAxis, zAxis); -} - - -QVector3D Transform::fromDirection(QVector3D d, float pitch) { - QVector3D ret; - d.normalize(); - ret[0] = M_PI - acos(d.z()); - ret[1] = pitch * deg2rad; - ret[2] = -atan2(d.x(), d.y()); - normalizeAngleRad(ret[0]); - normalizeAngleRad(ret[2]); - return ret * rad2deg; -} - - -QVector3D Transform::fromRotationMatrix(const QMatrix3x3 & m) { - //return QQuaternion::fromRotationMatrix(m); - float sy = sqrt(m(0,0) * m(0,0) + m(1,0) * m(1,0)); - bool singular = sy < 1.E-6; // If - float x, y, z; - if (!singular) { - x = atan2( m(2,1), m(2,2)); - y = atan2(-m(2,0), sy); - z = atan2( m(1,0), m(0,0)); - } else { - x = atan2(-m(1,2), m(1,1)); - y = atan2(-m(2,0), sy); - z = 0.; - } - return QVector3D(x, y, z) * rad2deg; -} - - -QMatrix3x3 Transform::toRotationMatrix(const QVector3D & r) { - QMatrix4x4 m; - if (r.z() != 0.f) m.rotate(r.z(), 0., 0., 1.); - if (r.y() != 0.f) m.rotate(r.y(), 0., 1., 0.); - if (r.x() != 0.f) m.rotate(r.x(), 1., 0., 0.); - return m.toGenericMatrix<3,3>(); -} - - -QMatrix4x4 Transform::rotateAround(const QVector3D & point, float angle, const QVector3D & axis) { - QMatrix4x4 m; - m.translate(point); - m.rotate(angle, axis); - m.translate(-point); - return m; -} - - -QMatrix4x4 Transform::rotateFromAxes(const QVector3D & xAxis, const QVector3D & yAxis, const QVector3D & zAxis) { - return QMatrix4x4(xAxis.x(), yAxis.x(), zAxis.x(), 0.0f, - xAxis.y(), yAxis.y(), zAxis.y(), 0.0f, - xAxis.z(), yAxis.z(), zAxis.z(), 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f); -} diff --git a/qglengine/core/gltransform.h b/qglengine/core/gltransform.h deleted file mode 100644 index f1e42de..0000000 --- a/qglengine/core/gltransform.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - QGL Transform - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLTRANSFORM_H -#define GLTRANSFORM_H - -#include -#include -#include -#include - - -class Transform { - friend QDataStream & operator >>(QDataStream & s, Transform & v); -public: - Transform(); - Transform & operator =(const Transform & t); - - float scale() const; - QVector3D scale3D() const; - QVector3D rotation() const; - QVector3D translation() const; - QMatrix4x4 matrix() const; - QMatrix4x4 matrixRotate() const; - QMatrix4x4 matrixScale() const; - QMatrix4x4 matrixRotateScale() const; - QVector3D direction() const; - - float rotationX() const; - float rotationY() const; - float rotationZ() const; - - void setScale(float s) {setScale(QVector3D(s, s, s));} - void setScale(const QVector3D & s); - void setScaleX(float s); - void setScaleY(float s); - void setScaleZ(float s); - - void setRotation(const QVector3D & r); - void setRotationX(float r); - void setRotationY(float r); - void setRotationZ(float r); - - void setTranslation(const QVector3D & t); - void setTranslationX(float t); - void setTranslationY(float t); - void setTranslationZ(float t); - - void setMatrix(const QMatrix4x4 & matrix); - void setDirty(bool yes = true) {m_matrixDirty = yes;} - - - static QQuaternion fromAxisAndAngle(const QVector3D & axis, float angle); - static QQuaternion fromAxisAndAngle(float x, float y, float z, float angle); - - static QQuaternion fromAxesAndAngles(const QVector3D & axis1, float angle1, - const QVector3D & axis2, float angle2); - static QQuaternion fromAxesAndAngles(const QVector3D & axis1, float angle1, - const QVector3D & axis2, float angle2, - const QVector3D & axis3, float angle3); - static QQuaternion fromAxes(const QVector3D & xAxis, const QVector3D & yAxis, const QVector3D & zAxis); - - static QVector3D fromDirection(QVector3D d, float pitch = 0.f); - static QVector3D fromRotationMatrix(const QMatrix3x3 & m); - static QMatrix3x3 toRotationMatrix(const QVector3D & r); - - static QMatrix4x4 rotateAround(const QVector3D & point, float angle, const QVector3D & axis); - static QMatrix4x4 rotateFromAxes(const QVector3D & xAxis, const QVector3D & yAxis, const QVector3D & zAxis); - -protected: - void buildMatrix() const; - - QVector3D m_scale; - QVector3D m_translation; - QVector3D m_eulerRotationAngles; - - mutable QMatrix4x4 m_matrix, m_matrixWT, m_matrixR, m_matrixS; - mutable bool m_matrixDirty; - -}; - - -inline QDataStream & operator <<(QDataStream & s, const Transform & v) { - //ChunkStream cs; - //cs.add(1, v.matrix()); - //s << cs.data(); return s; - s << v.matrix(); return s; -} -inline QDataStream & operator >>(QDataStream & s, Transform & v) { - //ChunkStream cs(s); - //while (!cs.atEnd()) { - // switch (cs.read()) { - // case 1: v.setMatrix(cs.getData()); break; - // } - //} - //return s; - QMatrix4x4 m; - s >> m; - v.setMatrix(m); - v.m_matrixDirty = true; - return s; -} - -#endif // QT3DCORE_QTRANSFORM_H diff --git a/qglengine/core/gltypes.cpp b/qglengine/core/gltypes.cpp deleted file mode 100644 index 22493de..0000000 --- a/qglengine/core/gltypes.cpp +++ /dev/null @@ -1,373 +0,0 @@ -/* - QGLView Types - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "glcamera.h" -#include "qglview.h" -#include "gltexture_manager.h" - -#include - -//__GLWidget__ * currentQGLView; -//QMutex globMutex; - - -QString readCharsUntilNull(QDataStream & s) { - QString str; - char ch; - s.readRawData(&ch, 1); - while (ch != '\0') { - str += ch; - s.readRawData(&ch, 1); - } - return str; -} - - -QString findFile(const QString & file, const QStringList & pathes) { - QFileInfo fi(QString(file).replace("\\", "/")); - //qDebug() << "search" << file << "in" << pathes; - if (fi.exists()) return fi.absoluteFilePath(); - QString fn = fi.fileName(); - if (fn.contains("/")) fn = fn.mid(fn.lastIndexOf("/")); - foreach (QString p, pathes) { - QFileInfoList fil = QDir(p).entryInfoList(QStringList(fn), QDir::Files | QDir::NoDotAndDotDot); - //qDebug() << "findFile" << fn << "in" << p << "->" << fil.size(); - if (!fil.isEmpty()) - return fil[0].absoluteFilePath(); - } - return QString(); -} - - -void glDrawQuad(QOpenGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x, GLfloat y, GLfloat w, GLfloat h) { - //glResetAllTransforms(); - glSetPolygonMode(GL_FILL); - glDisable(GL_LIGHTING); - glEnable(GL_TEXTURE_2D); - int loc = prog ? prog->attributeLocation("qgl_Color") : -1, - locv = prog ? prog->attributeLocation("qgl_Vertex") : -1, - loct = prog ? prog->attributeLocation("qgl_Texture") : -1, - locc = prog ? prog->attributeLocation("view_corner") : -1; - //if (prog) {qDebug() << locv << loct << locc;} - QOpenGLFunctions * glFuncs = QOpenGLContext::currentContext()->functions(); - if (prog) { - static const GLfloat cols [] = {1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f}; - static const GLfloat verts[] = {x, y, x+w, y, x, y+h, x+w, y+h}; - static const GLfloat texs [] = {0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f}; - GLfloat vcs[] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; - if (corner_dirs) { - vcs[0] = corner_dirs[0].x(); vcs[1] = corner_dirs[0].y(); vcs[2] = corner_dirs[0].z(); - vcs[3] = corner_dirs[1].x(); vcs[4] = corner_dirs[1].y(); vcs[5] = corner_dirs[1].z(); - vcs[6] = corner_dirs[2].x(); vcs[7] = corner_dirs[2].y(); vcs[8] = corner_dirs[2].z(); - vcs[9] = corner_dirs[3].x(); vcs[10] = corner_dirs[3].y(); vcs[11] = corner_dirs[3].z(); - } - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glFuncs->glBindBuffer(GL_ARRAY_BUFFER, 0); - glFuncs->glEnableVertexAttribArray(loc); - glFuncs->glVertexAttribPointer(loc, 3, GL_FLOAT, 0, 0, cols); - glFuncs->glEnableVertexAttribArray(locv); - glFuncs->glVertexAttribPointer(locv, 2, GL_FLOAT, 0, 0, verts); - glFuncs->glEnableVertexAttribArray(loct); - glFuncs->glVertexAttribPointer(loct, 2, GL_FLOAT, 0, 0, texs); - glFuncs->glEnableVertexAttribArray(locc); - glFuncs->glVertexAttribPointer(locc, 3, GL_FLOAT, 0, 0, vcs); - glFuncs->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glFuncs->glDisableVertexAttribArray(loc); - glFuncs->glDisableVertexAttribArray(locv); - glFuncs->glDisableVertexAttribArray(loct); - glFuncs->glDisableVertexAttribArray(locc); - } else { - glBegin(GL_TRIANGLE_STRIP); - glColor4f(1.f, 1.f, 1.f, 1.f); - glTexCoord2f(0.f, 0.f); glVertex2f(x, y); - glTexCoord2f(1.f, 0.f); glVertex2f(x+w, y); - glTexCoord2f(0.f, 1.f); glVertex2f(x, y+h); - glTexCoord2f(1.f, 1.f); glVertex2f(x+w, y+h); - glEnd(); - } -} - - -QMatrix4x4 getGLMatrix(GLenum matrix) { - GLfloat gm[16]; - glGetFloatv(matrix, gm); - float qm[16]; - for (int i = 0; i < 16; ++i) - qm[i] = gm[i]; - return QMatrix4x4(qm).transposed(); -} - - -void setGLMatrix(QMatrix4x4 matrix) { - GLfloat gm[16]; - float qm[16]; - matrix.transposed().copyDataTo(qm); - for (int i = 0; i < 16; ++i) - gm[i] = qm[i]; - glLoadMatrixf(gm); -} - - -void qglMultMatrix(const QMatrix4x4 & m) { - GLfloat gm[16]; - float qm[16]; - m.transposed().copyDataTo(qm); - for (int i = 0; i < 16; ++i) - gm[i] = qm[i]; - glMultMatrixf(gm); -} - - -void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, int width, int height, const GLenum & format, const GLenum & target) { - //glClearError(); - if (tex == 0) { - f->glGenTextures(1, &tex); - f->glBindTexture(target, tex); - } - //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - if (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_COMPONENT16 || format == GL_DEPTH_COMPONENT24 || format == GL_DEPTH_COMPONENT32) - f->glTexImage2D(target, 0, format, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, nullptr); - else { - int type = GL_UNSIGNED_BYTE; - int fmt = GL_RGBA; - if (format == GL_RGB32F || format == GL_RGB16F || format == GL_RGBA32F || format == GL_RGBA16F) - type = GL_FLOAT; - if (format == GL_RGB32F || format == GL_RGB16F || format == GL_RGB8 || format == GL_RGB) - fmt = GL_RGB; - f->glTexImage2D(target, 0, format, width, height, 0, fmt, type, nullptr); - //glGenerateMipmap(target); - //qDebug() << "glTexImage2D" << width << height << QString::number(t, 16); - } - //qDebug() << QString::number(glGetError(), 16); -} - - -void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, const QImage & image, const GLenum & format, const GLenum & target) { - if (tex == 0) { - f->glGenTextures(1, &tex); - } - f->glBindTexture(target, tex); - QImage im = image.mirrored(false, true).convertToFormat(QImage::Format_RGBA8888); - //const QImage & cim(im); - f->glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_REPEAT); - f->glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT); - f->glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT); - if (target == GL_TEXTURE_1D || target == GL_TEXTURE_2D || target == GL_TEXTURE_3D) { - f->glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - f->glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - f->glTexParameteri(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, 8); - } else { - f->glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - f->glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - } - glClearError(); - f->glTexImage2D(target, 0, format, im.width(), im.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, im.constBits()); - if (target == GL_TEXTURE_1D || target == GL_TEXTURE_2D || target == GL_TEXTURE_3D) { - f->glGenerateMipmap(target); - } - //qDebug() << target << format << tex << im.width() << im.height() << im.bits() << QString::number(glGetError(), 16); -} - - -QMatrix4x4 glMatrixPerspective(float angle, float aspect, float near_) { - QMatrix4x4 ret; - float t = 1.f / (tanf(angle * deg2rad / 2.f)), e = 2.4e-7f; - if (aspect >= 1.) { - ret(0, 0) = t / aspect; - ret(1, 1) = t; - } else { - ret(0, 0) = t; - ret(1, 1) = t * aspect; - } - ret(2, 2) = e - 1.f;//far_ / (far_ - near_) - 1.; - ret(2, 3) = (e - 2.f) * near_;//2. * far_ * near_ / (far_ - near_); - ret(3, 2) = -1.f; - ret(3, 3) = 0.f; - return ret; -} - - -QImage rotateQImageLeft(const QImage & im) { - QImage ri(im.height(), im.width(), im.format()); - QPainter p(&ri); - p.rotate(90); - p.drawImage(0, -im.height(), im); - p.end(); - return ri; -} - - -QImage rotateQImageRight(const QImage & im) { - QImage ri(im.height(), im.width(), im.format()); - QPainter p(&ri); - p.rotate(-90); - p.drawImage(-im.width(), 0, im); - p.end(); - return ri; -} - - - - -QColor colorFromString(const QString & str) { - QString s = str.trimmed(); - int i = s.indexOf("\t"); - float r, g, b; - r = s.left(i).toFloat(); s = s.right(s.length() - i - 1); i = s.indexOf("\t"); - g = s.left(i).toFloat(); s = s.right(s.length() - i - 1); - b = s.toFloat(); - return QColor(r * 255.f, g * 255.f, b * 255.f); -} - - -QVector3D orthToVector(const QVector3D & v, const float & scale) { - if (v.isNull()) return QVector3D(); - QVector3D rv, fn, sn; - if (v.x() != 0.f) rv.setZ(1.); - else if (v.y() != 0.f) rv.setX(1.); - else rv.setY(1.); - fn = QVector3D::crossProduct(v, rv).normalized(); - sn = QVector3D::crossProduct(v, fn).normalized(); - return fn * urand(scale) + sn * urand(scale); -} - - -QVector3D rotateVector(const QVector3D & v, const QVector3D & a) { - QMatrix4x4 m; - m.rotate(a.z(), 0., 0., 1.); - m.rotate(a.y(), 0., 1., 0.); - m.rotate(a.x(), 1., 0., 0.); - return m * v; -} - - -void setVectorLength(QVector3D & v, const float & l) { - float vl = v.length(); - if (vl == 0.f) return; - float c = l / vl; - v *= c; -} - - -void lengthenVector(QVector3D & v, const float & l) { - float vl = v.length(); - if (l == 0.f || vl == 0.f) return; - float c = 1.f + l / vl; - v *= c; -} - - -Vector2i::Vector2i(const QString & str) { - QString s = str.trimmed(); - int i = s.indexOf("\t"); - p0 = s.left(i).toInt(); s = s.right(s.length() - i - 1); - p1 = s.toInt(); -} - - -Vector3i::Vector3i(const QString & str) { - QString s = str.trimmed(); - int i = s.indexOf("\t"); - p0 = s.left(i).toInt(); s = s.right(s.length() - i - 1); i = s.indexOf("\t"); - p1 = s.left(i).toInt(); s = s.right(s.length() - i - 1); - p2 = s.toInt(); -} - - -void glEnableDepth() { - glEnable(GL_DEPTH_TEST); - //glDepthFunc(GL_GREATER); - glDepthFunc(GL_LESS); - glDepthMask(GL_TRUE); -} - - -void glDisableDepth() { - glDisable(GL_DEPTH_TEST); - glDepthMask(GL_FALSE); -} - - -void glClearFramebuffer(const QColor & color, bool depth) { - glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - //glClearDepth(0.); - if (depth) - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - else - glClear(GL_COLOR_BUFFER_BIT); -} - - - - -Box3D::Box3D(const QVector & points) { - x = y = z = width = length = height = angle_z = angle_xy = angle_roll = 0.f; - if (points.isEmpty()) return; - float ix, iy, iz, ax, ay, az; - ix = ax = points[0].x(); - iy = ay = points[0].y(); - iz = az = points[0].z(); - for (int i = 1; i < points.size(); ++i) { - ix = qMin(ix, points[i].x()); ax = qMax(ax, points[i].x()); - iy = qMin(iy, points[i].y()); ay = qMax(ay, points[i].y()); - iz = qMin(iz, points[i].z()); az = qMax(az, points[i].z()); - } - x = ix; - y = iy; - z = iz; - length = ax - ix; - width = ay - iy; - height = az - iz; -} - - -QVector Box3D::corners() const { - QVector ret; - ret << QVector3D(x, y, z) << QVector3D(x, y + width, z) << QVector3D(x, y, z + height) << QVector3D(x, y + width, z + height) - << QVector3D(x + length, y, z) << QVector3D(x + length, y + width, z) - << QVector3D(x + length, y, z + height) << QVector3D(x + length, y + width, z + height); - return ret; -} - - -Box3D & Box3D::operator |=(const Box3D & o) { - if (o.isEmpty()) return *this; - if (isEmpty()) *this = o; - else { - GLfloat mx = x + length, my = y + width, mz = z + height; - GLfloat omx = o.x + o.length, omy = o.y + o.width, omz = o.z + o.height; - x = qMin(x, o.x); y = qMin(y, o.y); z = qMin(z, o.z); - mx = qMax(mx, omx); my = qMax(my, omy); mz = qMax(mz, omz); - length = mx - x; width = my - y; height = mz - z; - } - return *this; -} - - -QVector3D vectorFromString(const QString & str) { - QTextStream s(const_cast(&str), QIODevice::ReadOnly); - QVector3D ret; - float f(0.f); - s >> f; ret.setX(f); - s >> f; ret.setY(f); - s >> f; ret.setZ(f); - return ret; -} diff --git a/qglengine/core/gltypes.h b/qglengine/core/gltypes.h deleted file mode 100644 index 5550643..0000000 --- a/qglengine/core/gltypes.h +++ /dev/null @@ -1,303 +0,0 @@ -/* - QGLView Types - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLTYPES_H -#define GLTYPES_H - -#if WIN32 || WIN64 || _WIN32 || _WIN64 || __WIN32__ || __WIN64__ -# define WINDOWS -#endif -#if __QNX__ || __QNXNTO__ -# define QNX -#endif -#ifdef __APPLE__ -# define MAC -#endif -#ifndef WINDOWS -# ifndef QNX -# ifndef MAC -# define LINUX -# endif -# endif -#endif -#if __GNUC__ -# define CC_GCC -#elif _MSC_VER -# define CC_VC -#endif - - -#include -//#ifndef WINDOWS -//# ifdef MAC -//# include -//# include -//# include -//# else -//# include -//# include -//# include -//# endif -//#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifndef QNX -# include -# include -#else -# include -# include -#endif -#include -#include "qglengine_version.h" - - -//#ifdef WINDOWS -//# define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF -//# define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE -//#endif - -#ifndef M_PI -# define M_PI 3.14159265358979323846 -#endif -#ifndef M_2PI -# define M_2PI 6.28318530717958647692 -#endif -#ifndef M_PI_3 -# define M_PI_3 1.04719755119659774615 -#endif - -#ifndef GL_RGBA16F -# define GL_RGBA16F GL_RGBA16F_ARB -#endif - -using std::complex; - -#ifndef PIP_VERSION -typedef long long llong; -typedef unsigned char uchar; -typedef unsigned short int ushort; -typedef unsigned int uint; -typedef unsigned long ulong; -typedef unsigned long long ullong; -typedef long double ldouble; - -const float deg2rad = atanf(1.f) / 45.f; -const float rad2deg = 45.f / atanf(1.f); - -# ifdef WINDOWS -inline int random() {return rand();} -# endif -#else -#define random randomi -#endif - -#ifdef CC_VC -inline float round(const float & v) {return floor(v + 0.5);} -#endif -inline float randomu() {return float(random()) / RAND_MAX;} - -inline const QSizeF operator *(const QSizeF & f, const QSizeF & s) {return QSizeF(f.width() * s.width(), f.height() * s.height());} -#ifndef PIP_VERSION -template inline void piSwap(T & f, T & s) {T t(f); f = s; s = t;} -template inline Type piMin(const Type & f, const Type & s) {return (f > s) ? s : f;} -template inline Type piMin(const Type & f, const Type & s, const Type & t) {return (f < s && f < t) ? f : ((s < t) ? s : t);} -template inline Type piMax(const Type & f, const Type & s) {return (f < s) ? s : f;} -template inline Type piMax(const Type & f, const Type & s, const Type & t) {return (f > s && f > t) ? f : ((s > t) ? s : t);} -template inline Type piClamp(const Type & v, const Type & min, const Type & max) {return (v > max ? max : (v < min ? min : v));} -inline ushort letobe_s(ushort v) {return (v << 8) | (v >> 8);} -inline uint letobe_i(const uint & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);} -#endif -// return [-1, 1] -inline float urand(const float & scale = 1.) {return ((float)rand() / RAND_MAX - .5f) * (scale + scale);} -// return [0, 1] -inline float uprand(const float & scale = 1.) {return ((float)rand() / RAND_MAX) * scale;} -QString readCharsUntilNull(QDataStream & s); -QString findFile(const QString & file, const QStringList & pathes); -inline QColor operator *(const QColor & c, float v) {return QColor(piClamp(c.red() * v, 0, 255), piClamp(c.green() * v, 0, 255), piClamp(c.blue() * v, 0, 255), piClamp(c.alpha() * v, 0, 255));} -inline QColor operator /(const QColor & c, float v) {return QColor(piClamp(c.red() / v, 0, 255), piClamp(c.green() / v, 0, 255), piClamp(c.blue() / v, 0, 255), piClamp(c.alpha() / v, 0, 255));} - - -inline void qglColor(const QColor & c) {glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF());} -inline void glClearError() {int c = 100; while (glGetError() != GL_NO_ERROR && --c > 0) glGetError();} -inline void glSetCapEnabled(GLenum cap, bool on = true) {if (on) glEnable(cap); else glDisable(cap);} -inline void glSetPolygonMode(GLenum mode) {glPolygonMode(GL_FRONT_AND_BACK, mode);} -inline void deleteGLTexture(QOpenGLExtraFunctions * f, GLuint & tex) {if (tex != 0) f->glDeleteTextures(1, &tex); tex = 0;} -void glEnableDepth(); -void glDisableDepth(); -void glClearFramebuffer(const QColor & color = Qt::black, bool depth = true); -void glDrawQuad(QOpenGLShaderProgram * prog = nullptr, QVector4D * corner_dirs = nullptr, GLfloat x = -1.f, GLfloat y = -1.f, GLfloat w = 2.f, GLfloat h = 2.f); -void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, int width, int height, const GLenum & format = GL_RGBA, const GLenum & target = GL_TEXTURE_2D); -void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, const QImage & image, const GLenum & format = GL_RGBA, const GLenum & target = GL_TEXTURE_2D); -QMatrix4x4 glMatrixPerspective(float angle, float aspect, float near_); -QImage rotateQImageLeft(const QImage & im); -QImage rotateQImageRight(const QImage & im); -inline QImage rotateQImage180(const QImage & im) {return im.mirrored(true, true);} - -class QGLView; -class MouseController; -class ObjectBase; -class AimedObject; -class Light; -class Camera; -class Texture; -class CubeTexture; -class Map; -class Material; -class TextureManager; -class Texture2DArray; -class Framebuffer; -class FramebufferMipmap; -class VertexObject; -class Mesh; -class Scene; -class RendererBase; -class Renderer; -class RendererMaterial; -class RendererService; -class RendererSelection; - -enum RenderPass { - rpSolid, - rpTransparent, -}; - -typedef QList ObjectBaseList; - -struct Box3D { - GLfloat x; - GLfloat y; - GLfloat z; - GLfloat width; - GLfloat length; - GLfloat height; - GLfloat angle_z; - GLfloat angle_xy; - GLfloat angle_roll; - Box3D() {x = y = z = width = length = height = angle_z = angle_xy = angle_roll = 0.f;} - Box3D(const QVector3D & center, GLfloat hwid, GLfloat hlen, GLfloat hhei) {x = center.x() - hwid; y = center.y() - hlen; z = center.z() - hhei; width = 2 * hwid; length = 2 * hlen; height = 2 * hhei; angle_z = angle_xy = angle_roll = 0.f;} - Box3D(const QVector & points); - bool isEmpty() const {return (qAbs(width) < 1E-6f) && (qAbs(length) < 1E-6f) && (qAbs(height) < 1E-6f);} - QVector3D randomPoint() const {return QVector3D(uprand(length) + x, uprand(width) + y, uprand(height) + z);} - QVector3D pos() const {return QVector3D(x, y, z);} - QVector3D size() const {return QVector3D(length, width, height);} - QVector3D center() const {return QVector3D(length / 2.f + x, width / 2.f + y, height / 2.f + z);} - QVector3D angles() const {return QVector3D(angle_xy, angle_roll, angle_z);} - QVector corners() const; - void setPos(const QVector3D & p) {x = p.x(); y = p.y(); z = p.z();} - void setAngles(const QVector3D & a) {angle_xy = a.x(); angle_roll = a.y(); angle_z = a.z();} - void setSize(const QVector3D & s) {length = s.x(); width = s.y(); height = s.z();} - Box3D & moveTo(const QVector3D & v) {x = v.x(); y = v.y(); z = v.z(); return *this;} - Box3D & move(const QVector3D & v) {x += v.x(); y += v.y(); z += v.z(); return *this;} - Box3D movedTo(const QVector3D & v) const {Box3D t(*this); t.x = v.x(); t.y = v.y(); t.z = v.z(); return t;} - Box3D moved(const QVector3D & v) const {Box3D t(*this); t.x += v.x(); t.y += v.y(); t.z += v.z(); return t;} - Box3D & operator |=(const Box3D & o); -}; - -inline QDebug operator <<(QDebug d, const Box3D & v) {d << "Box3D {start (" << v.x << "," << v.y << "," << v.z << "), size (" << v.length << "," << v.width << "," << v.height << ")}"; return d;} - - -#pragma pack(push, 1) -struct Vector2i { - Vector2i(int p0_ = 0, int p1_ = 0) {p0 = p0_; p1 = p1_;} - Vector2i(const QString & str); - Vector2i movedX(const int & o) {return Vector2i(p0 + o, p1);} - Vector2i movedY(const int & o) {return Vector2i(p0, p1 + o);} - Vector2i moved(const int & x, const int & y) {return Vector2i(p0 + x, p1 + y);} - GLint p0; - GLint p1; - bool operator ==(const Vector2i & o) const {return p0 == o.p0 && p1 == o.p1;} - bool operator !=(const Vector2i & o) const {return p0 != o.p0 || p1 != o.p1;} - void operator +=(int v) {p0 += v; p1 += v;} - QVector2D toQVector2D() const {return QVector2D(p0, p1);} -}; -#pragma pack(pop) - -inline Vector2i operator +(const Vector2i & f, const Vector2i & s) {return Vector2i(f.p0 + s.p0, f.p1 + s.p1);} -inline Vector2i operator -(const Vector2i & f, const Vector2i & s) {return Vector2i(f.p0 - s.p0, f.p1 - s.p1);} -inline Vector2i operator /(const Vector2i & f, const int & s) {return Vector2i(f.p0 / s, f.p1 / s);} -inline uint qHash(const Vector2i & v) {return v.p0 ^ ((v.p1 << 8) | (v.p1 >> 24));} -inline QDebug operator <<(QDebug d, const Vector2i & v) {d.nospace() << "{" << v.p0 << ", " << v.p1 << "}"; return d.space();} - -inline QDataStream & operator <<(QDataStream & s, const Vector2i & v) {s << v.p0 << v.p1; return s;} -inline QDataStream & operator >>(QDataStream & s, Vector2i & v) {s >> v.p0 >> v.p1; return s;} - - -#pragma pack(push, 1) -struct Vector3i { - Vector3i(int p0_ = 0, int p1_ = 0, int p2_ = 0) {p0 = p0_; p1 = p1_; p2 = p2_;} - Vector3i(const QString & str); - Vector3i movedX(const int & o) {return Vector3i(p0 + o, p1, p2);} - Vector3i movedY(const int & o) {return Vector3i(p0, p1 + o, p2);} - Vector3i movedZ(const int & o) {return Vector3i(p0, p1, p2 + o);} - Vector3i moved(const int & x, const int & y, const int & z) {return Vector3i(p0 + x, p1 + y, p2 + z);} - GLint p0; - GLint p1; - GLint p2; - bool operator ==(const Vector3i & o) const {return p0 == o.p0 && p1 == o.p1 && p2 == o.p2;} - bool operator !=(const Vector3i & o) const {return p0 != o.p0 || p1 != o.p1 || p2 != o.p2;} - void operator +=(int v) {p0 += v; p1 += v; p2 += v;} - QVector3D toQVector3D() const {return QVector3D(p0, p1, p2);} -}; -#pragma pack(pop) - -inline Vector3i operator +(const Vector3i & f, const Vector3i & s) {return Vector3i(f.p0 + s.p0, f.p1 + s.p1, f.p2 + s.p2);} -inline Vector3i operator -(const Vector3i & f, const Vector3i & s) {return Vector3i(f.p0 - s.p0, f.p1 - s.p1, f.p2 - s.p2);} -inline Vector3i operator /(const Vector3i & f, const int & s) {return Vector3i(f.p0 / s, f.p1 / s, f.p2 / s);} -inline uint qHash(const Vector3i & v) {return v.p0 ^ ((v.p1 << 8) | (v.p1 >> 24)) ^ ((v.p2 << 16) | (v.p2 >> 16));} -inline QDebug operator <<(QDebug d, const Vector3i & v) {d.nospace() << "{" << v.p0 << ", " << v.p1 << ", " << v.p2 << "}"; return d.space();} - -inline QDataStream & operator <<(QDataStream & s, const Vector3i & v) {s << v.p0 << v.p1 << v.p2; return s;} -inline QDataStream & operator >>(QDataStream & s, Vector3i & v) {s >> v.p0 >> v.p1 >> v.p2; return s;} - - -QVector3D vectorFromString(const QString & str); -QColor colorFromString(const QString & str); -inline QVector4D QColor2QVector(const QColor & c) {return QVector4D(c.redF(), c.greenF(), c.blueF(), c.alphaF());} -inline float cosABV(const QVector3D & v0, const QVector3D & v1) { - float l = v0.length() * v1.length(); - if (l == 0.f) return 0.; - return (QVector3D::dotProduct(v0, v1)) / l; -} -inline void normalizeAngleRad(float & a) {while (a < 0.) a += M_2PI; while (a >= M_2PI) a -= M_2PI;} -inline void normalizeAngleDeg(float & a) {while (a < 0.) a += 360. ; while (a >= 360. ) a -= 360. ;} -inline QVector3D projection(const QVector3D & v, const QVector3D & to) {return to.normalized() * v.length() * cosABV(v, to);} -QVector3D orthToVector(const QVector3D & v, const float & scale = 1.); -QVector3D rotateVector(const QVector3D & v, const QVector3D & a); -void setVectorLength(QVector3D & v, const float & l); -void lengthenVector(QVector3D & v, const float & l); -inline float squareLength(const QVector3D & from, const QVector3D & to) {return (to.x() - from.x())*(to.x() - from.x()) + (to.y() - from.y())*(to.y() - from.y()) + (to.z() - from.z())*(to.z() - from.z());} -inline QVector3D directionFromAngles(const QVector3D & a) {return rotateVector(QVector3D(1., 0., 0.), a);} -inline float frac(const float & x, const float & b) {return x - int(x / b) * b;} - - -#endif // GLTYPES_H diff --git a/qglengine/core/glvertexobject.cpp b/qglengine/core/glvertexobject.cpp deleted file mode 100644 index e4a5437..0000000 --- a/qglengine/core/glvertexobject.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - QGL VertexObject - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#define GL_GLEXT_PROTOTYPES -#include -#include "glvertexobject.h" - -using namespace QGLEngineShaders; - - -VertexObject::VertexObject(): - buffer_obj (GL_ARRAY_BUFFER, GL_STREAM_DRAW), - buffer_sel (GL_ARRAY_BUFFER, GL_STREAM_DRAW) { - vao_ = 0; - buffers_binded = false; - objects_changed = selected_changed = true; -} - - -VertexObject::~VertexObject() { -} - - -void VertexObject::init(QOpenGLExtraFunctions * f) { - if (!isInit()) { - buffer_obj.init(f); - buffer_sel.init(f); - f->glGenVertexArrays(1, &vao_); - } -} - - -void VertexObject::destroy(QOpenGLExtraFunctions * f) { - if (vao_ != 0) { - buffer_obj.destroy(f); - buffer_sel.destroy(f); - f->glDeleteVertexArrays(1, &vao_); - } - vao_ = 0; -} - - -void VertexObject::bind(QOpenGLExtraFunctions * f) { - //qDebug() << "bind" << target_ << buffer_; - f->glBindVertexArray(vao_); -} - - -void VertexObject::release(QOpenGLExtraFunctions * f) { - f->glBindVertexArray(0); -} - - -void VertexObject::bindBuffers(QOpenGLExtraFunctions * f, Buffer & geom, Buffer & elem, bool force) { - if (!force && buffers_binded) return; - buffers_binded = true; - - init(f); - bind(f); - - geom.bind(f); - prepareDrawGeom(f); - - elem.bind(f); - - buffer_obj.bind(f); - prepareDrawObj(f); - - buffer_sel.bind(f); - prepareDrawSel(f); - - release(f); -} - - -void VertexObject::loadObject(QOpenGLExtraFunctions * f, const Object & object) { - loadBuffer(f, buffer_obj, &object, sizeof(Object)); -} - - -void VertexObject::loadObjects(QOpenGLExtraFunctions * f, const QVector & objects) { - loadBuffer(f, buffer_obj, objects.constData(), objects.size() * sizeof(Object)); -} - - -void VertexObject::loadSelections(QOpenGLExtraFunctions * f, const QVector & sels) { - loadBuffer(f, buffer_sel, sels.constData(), sels.size()); -} - - -void VertexObject::draw(QOpenGLExtraFunctions * f, GLenum geom_type, int vert_cout, int obj_count) { - bind(f); - f->glDrawElementsInstanced(geom_type, vert_cout, GL_UNSIGNED_INT, 0, obj_count); - release(f); -} - - -void VertexObject::loadBuffer(QOpenGLExtraFunctions * f, Buffer & buf, const void * data, int size) { - buf.init(f); - if (!data) return; - buf.bind(f); - buf.resize(f, size); - buf.load(f, data, size); -} diff --git a/qglengine/core/glvertexobject.h b/qglengine/core/glvertexobject.h deleted file mode 100644 index 58b0894..0000000 --- a/qglengine/core/glvertexobject.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - QGL VertexObject - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLVERTEXOBJECT_H -#define GLVERTEXOBJECT_H - -#include "glbuffer.h" -#include "glshaders_types.h" - - -class VertexObject -{ - friend class Mesh; -public: - VertexObject(); - ~VertexObject(); - - void init (QOpenGLExtraFunctions * f); - void destroy (QOpenGLExtraFunctions * f); - - void bind (QOpenGLExtraFunctions * f); - void release (QOpenGLExtraFunctions * f); - - void bindBuffers (QOpenGLExtraFunctions * f, Buffer & geom, Buffer & elem, bool force = false); - void loadObject (QOpenGLExtraFunctions * f, const QGLEngineShaders::Object & object); - void loadObjects (QOpenGLExtraFunctions * f, const QVector & objects); - void loadSelections(QOpenGLExtraFunctions * f, const QVector & sels); - - void draw(QOpenGLExtraFunctions * f, GLenum geom_type, int vert_cout, int obj_count); - - GLuint ID() const {return vao_;} - bool isInit() const {return vao_ != 0;} - - bool isObjectsChanged() const {return objects_changed;} - bool isSelectionChanged() const {return selected_changed;} - void setObjectsChanged(bool yes = true) {objects_changed = yes;} - void setSelectionChanged(bool yes = true) {selected_changed = yes;} - -private: - void loadBuffer(QOpenGLExtraFunctions * f, Buffer & buf, const void * data, int size); - - GLuint vao_; - Buffer buffer_obj, buffer_sel; - bool buffers_binded, objects_changed, selected_changed; - -}; - - -#endif // GLVERTEXOBJECT_H diff --git a/qglengine/core/hdr.cpp b/qglengine/core/hdr.cpp deleted file mode 100644 index d1e2248..0000000 --- a/qglengine/core/hdr.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - QGL HDR - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "hdr_p.h" -#include "qmath.h" - -#define RGBE_DATA_RED 2 -#define RGBE_DATA_GREEN 1 -#define RGBE_DATA_BLUE 0 -/* number of floats per pixel */ -#define RGBE_DATA_SIZE 3 - - -void rgbe2float(float *red, float *green, float *blue, uchar rgbe[4]) { - float f; - if (rgbe[3]) { - f = static_cast(ldexp(1.0,rgbe[3]-(int)(128+8))); - *red = rgbe[0] * f; - *green = rgbe[1] * f; - *blue = rgbe[2] * f; - } - else - *red = *green = *blue = 0.0; -} - - -/* simple read routine. will not correctly handle run length encoding */ -bool RGBE_ReadPixels(QDataStream * fp, float * data, int numpixels) { - uchar rgbe[4]; - while(numpixels-- > 0) { - if (fp->readRawData((char*)rgbe, sizeof(rgbe)) < 1) - return false; - rgbe2float(&data[RGBE_DATA_RED], &data[RGBE_DATA_GREEN], &data[RGBE_DATA_BLUE],rgbe); - data += RGBE_DATA_SIZE; - } - return true; -} - - -bool RGBE_ReadPixels_RLE(QDataStream * fp, float * data, int scanline_width, int num_scanlines) { - uchar rgbe[4], *ptr, *ptr_end; - int i, count; - uchar buf[2]; - QByteArray scanline_buffer; - - if ((scanline_width < 8)||(scanline_width > 0x7fff)) - /* run length encoding is not allowed so read flat*/ - return RGBE_ReadPixels(fp,data,scanline_width*num_scanlines); - scanline_buffer.resize(4*scanline_width); - /* read in each successive scanline */ - while(num_scanlines > 0) { - if (fp->readRawData((char*)rgbe,sizeof(rgbe)) < 1) { - return false; - } - if ((rgbe[0] != 2)||(rgbe[1] != 2)||(rgbe[2] & 0x80)) { - /* this file is not run length encoded */ - rgbe2float(&data[RGBE_DATA_RED],&data[RGBE_DATA_GREEN],&data[RGBE_DATA_BLUE],rgbe); - data += RGBE_DATA_SIZE; - return RGBE_ReadPixels(fp,data,scanline_width*num_scanlines-1); - } - if ((((int)rgbe[2])<<8 | rgbe[3]) != scanline_width) { - return false; - } - ptr = (uchar*)scanline_buffer.data(); - /* read each of the four channels for the scanline into the buffer */ - for(i=0;i<4;i++) { - ptr_end = (uchar*)scanline_buffer.data() + ((i+1)*scanline_width); - while(ptr < ptr_end) { - if (fp->readRawData((char*)buf,sizeof(buf[0])*2) < 1) { - return false; - } - if (buf[0] > 128) { - /* a run of the same value */ - count = buf[0]-128; - if ((count == 0)||(count > ptr_end - ptr)) { - return false; - } - while(count-- > 0) - *ptr++ = buf[1]; - } - else { - /* a non-run */ - count = buf[0]; - if ((count == 0)||(count > ptr_end - ptr)) { - return false; - } - *ptr++ = buf[1]; - if (--count > 0) { - if (fp->readRawData((char*)ptr,sizeof(*ptr)*count) < 1) { - return false; - } - ptr += count; - } - } - } - } - /* now convert data from buffer into floats */ - for(i=0;i. -*/ - -#ifndef HDR_P_H -#define HDR_P_H - -#include - -bool RGBE_ReadPixels_RLE(QDataStream * fp, float * data, int scanline_width, int num_scanlines); - -#endif // HDR_P_H diff --git a/qglengine/formats/loader_assimp.cpp b/qglengine/formats/loader_assimp.cpp deleted file mode 100644 index fe53b77..0000000 --- a/qglengine/formats/loader_assimp.cpp +++ /dev/null @@ -1,267 +0,0 @@ -/* - QGL Loader Assimp - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "loader_assimp.h" -#include "glscene.h" -#include "glmesh.h" -#include "glmaterial.h" -#include "globject.h" -#include -#include -#include -#include -#include - -QString fromAiString (const aiString & s) {return QString::fromLocal8Bit(s.C_Str());} -QColor fromAiColor (const aiColor4D & c) {return QColor::fromRgbF(piClamp(c.r, 0.f, 1.f), piClamp(c.g, 0.f, 1.f), piClamp(c.b, 0.f, 1.f));} -QVector3D fromAiVector3D(const aiVector3D & v) {return QVector3D(v.x, v.y, v.z);} - Vector3i fromAiFace (const aiFace & v) {return Vector3i(v.mIndices[0], v.mIndices[1], v.mIndices[2]);} -QMatrix4x4 fromAiMatrix4D(const aiMatrix4x4 & v) {return QMatrix4x4(v.a1, v.a2, v.a3, v.a4, - v.b1, v.b2, v.b3, v.b4, - v.c1, v.c2, v.c3, v.c4, - v.d1, v.d2, v.d3, v.d4);} -bool isAiMeshTriangles(const aiMesh * m) {return (m->mPrimitiveTypes & aiPrimitiveType_TRIANGLE) == aiPrimitiveType_TRIANGLE;} - - -Mesh * assimpMesh(const aiMesh * m) { - if (!m) return 0; - if (!isAiMeshTriangles(m)) return 0; - Mesh * ret = new Mesh(); - int vcnt = m->mNumVertices, tcnt = m->mNumFaces; - - QVector & v(ret->vertices()); v.resize(vcnt); - QVector & t(ret->texcoords()); t.resize(vcnt); - QVector< Vector3i> & ind(ret->indicesTriangles()); - - for (int i = 0; i < vcnt; ++i) - v[i] = fromAiVector3D(m->mVertices[i]); - - if (m->HasNormals()) { - QVector & n(ret->normals()); - n.resize(vcnt); - for (int i = 0; i < vcnt; ++i) - n[i] = fromAiVector3D(m->mNormals[i]); - } - - if (m->HasTextureCoords(0)) { - for (int i = 0; i < vcnt; ++i) - t[i] = fromAiVector3D(m->mTextureCoords[0][i]).toVector2D(); - } - - if (m->HasFaces()) { - ind.resize(tcnt); - for (int i = 0; i < tcnt; ++i) - ind[i] = fromAiFace(m->mFaces[i]); - } else { - tcnt = vcnt / 3; - ind.resize(tcnt); - int si = 0; - for (int i = 0; i < tcnt; ++i) { - si = i+i+i; - ind[i] = Vector3i(si, si+1, si+2); - } - } - - //qDebug() << "add mesh" << v.size() << ret->normals().size() << ret->texcoords().size() << ret->indices().size(); - - return ret; -} - - -QColor aiMatColor(const aiMaterial * m, const char * key, uint s0, uint s1, const QColor & def = Qt::white) { - aiColor4D col; - aiReturn r = m->Get(key, s0, s1, col); - //qDebug() << key << r << col.r << col.g << col.b; - if (r != aiReturn_SUCCESS) return def; - return fromAiColor(col); -} -float aiMatFloat(const aiMaterial * m, const char * key, uint s0, uint s1, float def = 0.f) { - float ret; - aiReturn r = m->Get(key, s0, s1, ret); - if (r != aiReturn_SUCCESS) return def; - return ret; -} -QString aiMatString(const aiMaterial * m, const char * key, uint s0, uint s1) { - aiString p; - aiReturn r = const_cast(m)->Get(key, s0, s1, p); - //qDebug() << "GetTexture" << key << s0 << r << fromAiString(p); - if (r != aiReturn_SUCCESS) return QString(); - return fromAiString(p); -} -Material * assimpMaterial(const aiMaterial * m) { - if (!m) return 0; - Material * ret = new Material(); - ///WARNING: no function GetName() in aiMaterial in stable release - //ret->name = fromAiString(const_cast(m)->GetName()); - aiString name; - const_cast(m)->Get(AI_MATKEY_NAME,name); - ret->name = fromAiString(name); - //qDebug() << "mat" << ret->name; - //for (int i = 0; i < m->mNumProperties; ++i) { - // qDebug()<< fromAiString(m->mProperties[i]->mKey);// << "=" << aiMatFloat(m, m->mProperties[i]->mKey.C_Str(), 0, 0); - //} - ret->color_diffuse = aiMatColor(m, AI_MATKEY_COLOR_DIFFUSE); - ret->color_emission = aiMatColor(m, AI_MATKEY_COLOR_EMISSIVE); - float shine = aiMatFloat(m, AI_MATKEY_SHININESS, -1.f); - if (shine >= 0) { - ret->map_roughness.color_amount = 0.8f - (shine / 100.f * 0.6f); - //qDebug() << "shine" << shine; - } - ret->map_diffuse .bitmap_path = aiMatString(m, AI_MATKEY_TEXTURE_DIFFUSE(0)); - ret->map_normal .bitmap_path = aiMatString(m, AI_MATKEY_TEXTURE_NORMALS(0)); - //ret->map_metalness.bitmap_path = aiMatString(m, AI_MATKEY_TEXTURE_SPECULAR(0)); - ret->map_roughness.bitmap_path = aiMatString(m, AI_MATKEY_TEXTURE_SHININESS(0)); - ret->map_emission .bitmap_path = aiMatString(m, AI_MATKEY_TEXTURE_EMISSIVE(0)); - ret->transparency = 1.f - aiMatFloat(m, AI_MATKEY_OPACITY, 1.f); - ret->detectMaps(); - ret->setTypes(); - return ret; -} - - -Light * assimpLight(const aiLight * l) { - if (!l) return 0; - if (l->mType != aiLightSource_POINT && l->mType != aiLightSource_SPOT) - return 0; - Light * ret = new Light(); - ret->setName(fromAiString(l->mName)); - ret->setPos(fromAiVector3D(l->mPosition)); - ret->setDirection(fromAiVector3D(l->mDirection)); - ret->decay_const = l->mAttenuationConstant ; - ret->decay_linear = l->mAttenuationLinear ; - ret->decay_quadratic = l->mAttenuationQuadratic; - ret->angle_start = l->mAngleInnerCone * rad2deg; - ret->angle_end = l->mAngleOuterCone * rad2deg; - if (l->mType == aiLightSource_SPOT) - ret->light_type = Light::Cone; - QVector3D col(l->mColorDiffuse.r, l->mColorDiffuse.g, l->mColorDiffuse.b); - ret->intensity = col.length(); - col /= ret->intensity; - ret->setColor(QColor::fromRgbF(col[0], col[1], col[2])); - return ret; -} - - -ObjectBaseList assimpObject(const aiNode * n, const QVector & meshes, aiMesh ** ai_meshes, - const QVector & materials, - const QMap & light_by_name, QVector & out_lights) { - if (!n) return ObjectBaseList(); - ObjectBaseList ret; - ObjectBase * obj = 0; - QString name = fromAiString(n->mName); - Light * light = light_by_name.value(name, 0); - if (light) { - obj = light->clone(); - out_lights << (Light*)obj; - } else - obj = new ObjectBase(); - obj->setName(name); - obj->setMatrix(fromAiMatrix4D(n->mTransformation)); - ret << obj; - //qDebug() << "add object" << ret << ret->name(); - if (!light) { - //qDebug() << name << "has" << n->mNumMeshes << "meshes"; - for (uint i = 0; i < n->mNumMeshes; ++i) { - int mi = n->mMeshes[i]; - if (meshes[mi]) { - if (obj->mesh()) { - obj = obj->clone(false); - ret << obj; - } - obj->setMesh(meshes[mi]); - int mati = ai_meshes[mi]->mMaterialIndex; - if (mati >= 0 || mati < materials.size()) - obj->setMaterial(materials[mati]); - //ret->setMesh(meshes[mi]); - //qDebug() << "set mesh" << mi << ret->mesh(); - //break; - } - } - } - for (uint i = 0; i < n->mNumChildren; ++i) { - ObjectBaseList cl = assimpObject(n->mChildren[i], meshes, ai_meshes, materials, light_by_name, out_lights); - foreach (ObjectBase * c, cl) - obj->addChild(c); - } - - return ret; -} - - -Scene * loadScene(const QString & filepath) { - if (filepath.isEmpty()) return 0; - qDebug() << "[Loader Assimp] Import" << filepath << "..."; - Assimp::Importer importer; - const aiScene * ais = importer.ReadFile(filepath.toUtf8(), aiProcess_Triangulate | - aiProcess_SortByPType | - aiProcess_GenUVCoords | - aiProcess_TransformUVCoords); - if (!ais) { - qDebug() << "[Loader Assimp] Error: \"" + QString(importer.GetErrorString()) + "\""; - return 0; - } - qDebug() << "[Loader Assimp] Imported" << ais->mNumMeshes << "meshes"; - QVector meshes; - for (uint i = 0; i < ais->mNumMeshes; ++i) - meshes << assimpMesh(ais->mMeshes[i]); - QVector materials; - for (uint i = 0; i < ais->mNumMaterials; ++i) - materials << assimpMaterial(ais->mMaterials[i]); - QVector lights; - for (uint i = 0; i < ais->mNumLights; ++i) - lights << assimpLight(ais->mLights[i]); - QMap light_by_name; - foreach (Light * l, lights) - if (l) - light_by_name[l->name()] = l; - - QVector out_lights; - ObjectBaseList rootl = assimpObject(ais->mRootNode, meshes, ais->mMeshes, materials, light_by_name, out_lights); - if (rootl.isEmpty()) return 0; - ObjectBase * root = rootl[0]; - root->transferTransformToChildren(true); - - ObjectBaseList rcl = root->children(true); - foreach (ObjectBase * c, rcl) { - foreach (Light * l, out_lights) { - if (c->name() == (l->name() + ".Target")) { - l->setDistance((l->worldPos() - c->worldPos()).length()); - delete c; - break; - } - } - } - root->cleanTree(); - - Scene * scene = new Scene(); - scene->setName(root->name()); - foreach (ObjectBase * o, root->children()) - scene->addObject(o); - lights.removeAll(0); - qDeleteAll(lights); - - return scene; -} - - -QStringList supportedFormats() { - Assimp::Importer importer; - aiString ret; - importer.GetExtensionList(ret); - return fromAiString(ret).toLower().split(";"); -} diff --git a/qglengine/formats/loader_assimp.h b/qglengine/formats/loader_assimp.h deleted file mode 100644 index 348c32f..0000000 --- a/qglengine/formats/loader_assimp.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - QGL Loader Assimp - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef LOADER_ASSIMP_H -#define LOADER_ASSIMP_H - -#include "gltypes.h" - -Scene * loadScene(const QString & filepath); -QStringList supportedFormats(); - -#endif // LOADER_ASSIMP_H diff --git a/qglengine/formats/loader_qgl.cpp b/qglengine/formats/loader_qgl.cpp deleted file mode 100644 index 9e04190..0000000 --- a/qglengine/formats/loader_qgl.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - QGL Loader QGL - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "loader_qgl.h" -#include "glscene.h" -#include - - -Scene * loadFromQGLFile(const QString & filepath) { - QFile f(filepath); - if (!f.exists()) { - qDebug() << "[Loader QGL] Error: can`t open \"" + filepath + "\""; - return 0; - } - f.open(QIODevice::ReadOnly); - QDataStream s(&f); - s.setVersion(QDataStream::Qt_5_0); - char sign[4]; - s.readRawData(sign, 4); - if ((sign[0] != 'Q') || (sign[1] != 'G') || (sign[2] != 'L') || (sign[3] != 'E')) { - qDebug() << "[Loader QGL] Error: \"" + filepath + "\" is not valid QGLEngine file!"; - return 0; - } - ushort version = 0x1; - f.peek((char*)&version, 2); - if (version != 1) { - qDebug() << "[Loader QGL] Error: \"" + filepath + "\" unsupported version!"; - return 0; - } - Scene * ret = 0; - s.skipRawData(2); - s >> ret; - //root->buildTransform(); - qDebug() << "[Loader QGL] Loaded" << ret->objectsCount(true) << "objects from" << filepath; - return ret; -} - - -bool saveToQGLFile(const QString & filepath, const Scene * scene) { - QFile f(filepath); - if (!f.open(QIODevice::ReadWrite)) - return false; - f.resize(0); - QDataStream s(&f); - s.setVersion(QDataStream::Qt_5_0); - char sign[4] = {'Q', 'G', 'L', 'E'}; - ushort version = 0x1; - s.writeRawData(sign, 4); - s.writeRawData((char*)&version, 2); - s << scene; - return true; -} diff --git a/qglengine/formats/loader_qgl.h b/qglengine/formats/loader_qgl.h deleted file mode 100644 index 72aed12..0000000 --- a/qglengine/formats/loader_qgl.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - QGL Loader QGL - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef LOADER_QGL_H -#define LOADER_QGL_H - -#include "gltypes.h" -#include - -Scene * loadFromQGLFile(const QString & filepath); -bool saveToQGLFile(const QString & filepath, const Scene * scene); - -#endif // LOADER_QGL_H diff --git a/qglengine/glcamera.cpp b/qglengine/glcamera.cpp deleted file mode 100644 index d7dda9a..0000000 --- a/qglengine/glcamera.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - QGL Camera - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "gltypes.h" -#include "qglview.h" - - -Camera::Camera() { - type_ = glCamera; - fov_ = 60.; - roll_ = 0.; - //setRotationX(90.f); - depth_start = 0.1f; - mirror_x = mirror_y = false; -} - - -QMatrix4x4 Camera::offsetMatrix() const { - QMatrix4x4 ret; - ret.translate(parent_ ? -offset_ : -aim()); - return ret; -} - -/* -void Camera::localTransform(QMatrix4x4 & m) { - return; - if (parent_) - m *= parent_->worldTransform(); - QMatrix4x4 ret; - //qDebug() << "local camera"; - ret.translate(0., 0., -distance()); - ret.rotate(angles_.y(), 1., 0., 0.); - ret.rotate(angles_.x(), 0., 1., 0.); - ret.rotate(angles_.z(), 0., 0., 1.); - //m *= ret.inverted(); -} -*/ - -void Camera::assign(const Camera & c) { - trans = c.trans; - aim_dist = c.aim_dist; - fov_ = c.fov_; - mirror_x = c.mirror_x; - mirror_y = c.mirror_y; - depth_start = c.depth_start; - buildTransform(); -} - - -ObjectBase * Camera::clone(bool withChildren) { - Camera * o = new Camera(*this); - //GLObjectBase::clone(withChildren); - o->is_init = false; - o->name_ = name_;// + "_copy"; - o->scene_ = nullptr; - o->children_.clear(); - if (withChildren) { - for (int i = 0; i < children_.size(); ++i) - o->addChild(children_[i]->clone(withChildren)); - } - o->trans = trans; - o->aim_dist = aim_dist; - o->fov_ = fov_; - o->roll_ = roll_; - o->mirror_x = mirror_x; - o->mirror_y = mirror_y; - o->depth_start = depth_start; - o->meta = meta; - return o; -} - - -QMatrix4x4 Camera::viewMatrix() const { - QMatrix4x4 ret; - //qDebug() << pos() << aim(); - ret.translate(0., 0., -distance()); - ret.rotate(-roll_, 0., 0., 1.); - ret *= trans.matrixRotateScale().inverted(); - //ret.rotate(angles_.y(), 1., 0., 0.); - //ret.rotate(angles_.x(), 0., 1., 0.); - //pm.translate(-aim_); - if (parent_) { - QMatrix4x4 pmat = parent_->worldTransform(); - offset_ = pmat.column(3).toVector3D(); - pmat(0, 3) = pmat(1, 3) = pmat(2, 3) = 0.; - pmat.translate(aim()); - ret *= pmat.inverted(); - } - return ret; -} - - -QMatrix4x4 Camera::projectionMatrix(double aspect) const { - return glMatrixPerspective(fov_, aspect, depth_start); -} diff --git a/qglengine/glcamera.h b/qglengine/glcamera.h deleted file mode 100644 index c8743f8..0000000 --- a/qglengine/glcamera.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - QGL Camera - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLCAMERA_H -#define GLCAMERA_H - -#include "globject.h" - -//extern QMatrix4x4 globCameraMatrix; -//extern Camera * currentCamera; - -class Camera: public AimedObject -{ - friend class QGLView; - friend class GLParticlesSystem; - friend QDataStream & operator <<(QDataStream & s, const ObjectBase * p); - friend QDataStream & operator >>(QDataStream & s, ObjectBase *& p); -public: - Camera(); - - void setFOV(const float & f) {fov_ = f;} - void setAngles(const QVector3D & a) {setRotation(a);} - void setAngleZ(const float & a) {setRotationZ(a);} - void setAngleXY(const float & a) {setRotationX(a);} - void setAngleRoll(const float & a) {roll_ = a;} - void setDepthStart(const float & d) {depth_start = d;} - void setMirrorX(bool yes) {mirror_x = yes;} - void setMirrorY(bool yes) {mirror_y = yes;} - - float FOV() const {return fov_;} - float angleZ() const {return rotationZ();} - float angleXY() const {return rotationX();} - float angleRoll() const {return roll_;} - float depthStart() const {return depth_start;} - bool isMirrorX() const {return mirror_x;} - bool isMirrorY() const {return mirror_y;} - void assign(const Camera & c); - - virtual ObjectBase * clone(bool withChildren = true); - QMatrix4x4 viewMatrix() const; - QMatrix4x4 projectionMatrix(double aspect) const; - QMatrix4x4 offsetMatrix() const; - - QMatrix4x4 fullViewMatrix() const {return viewMatrix() * offsetMatrix();} - -private: - mutable QVector3D offset_; - GLfloat fov_, roll_; - GLfloat depth_start; - bool mirror_x; - bool mirror_y; - -}; - -#endif // GLCAMERA_H diff --git a/qglengine/globject.cpp b/qglengine/globject.cpp deleted file mode 100644 index bad61ee..0000000 --- a/qglengine/globject.cpp +++ /dev/null @@ -1,717 +0,0 @@ -/* - QGL ObjectBase & Light - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "globject.h" -#include "glcamera.h" -#include "glscene.h" -#include "glmesh.h" -#include -//static int _count = 0; - -ObjectBase::ObjectBase(Mesh * geom, Material * mat) { - type_ = glMesh; - render_mode = View; - prev_pass = rpSolid; - parent_ = nullptr; - color_ = Qt::white; - is_root = is_init = selected_ = false; - visible_ = accept_fog = accept_light = cast_shadow = rec_shadow = select_ = true; - line_width = -1.; - id_ = 0; - blend_src = GL_SRC_ALPHA; - blend_dest = GL_ONE_MINUS_SRC_ALPHA; - type_ = glMesh; - raw_matrix = selected_aim = false; - mat_.setToIdentity(); - scene_ = nullptr; - mesh_ = geom; - material_ = mat; - //qDebug() << "ObjectBase, now" << ++_count; -} - - -ObjectBase::~ObjectBase() { - //qDebug() << "~ObjectBase, now" << --_count; - if (parent_) parent_->children_.removeAll(this); - if (scene_) { - scene_->__objectDeleted(this); - scene_->setTreeChanged(); - scene_->setTreeStructChanged(); - } - foreach (ObjectBase * c, children_) { - c->parent_ = nullptr; - delete c; - } -} - - -ObjectBase * ObjectBase::clone(bool withChildren) { - ObjectBase * o = new ObjectBase(); - o->prev_pass = prev_pass; - o->is_init = false; - o->accept_light = accept_light; - o->accept_fog = accept_fog; - o->visible_ = visible_; - o->color_ = color_; - o->type_ = type_; - o->raw_matrix = raw_matrix; - o->mat_ = mat_; - o->trans = trans; - o->itransform_ = itransform_; - o->bound = bound; - o->name_ = name_;// + "_copy"; - o->blend_src = blend_src; - o->blend_dest = blend_dest; - o->pos_h = pos_h; - o->material_ = material_; - o->mesh_ = mesh_; - o->meta = meta; - o->scene_ = nullptr; - if (withChildren) { - for (int i = 0; i < children_.size(); ++i) - o->addChild(children_[i]->clone(withChildren)); - } - return o; -} - - -void ObjectBase::destroy() { - if (mesh_) delete mesh_; -} - - -void ObjectBase::init() { - calculateBoundingBox(); - //material_.reflection.create(); - //qDebug() << "init" << vbo.buffer_; - is_init = true; -} - - -RenderPass ObjectBase::pass() const { - RenderPass ret = rpSolid; - if (material_) - if (material_->hasTransparency()) - ret = rpTransparent; - return ret; -} - - -void ObjectBase::setScene(Scene * v) { - scene_ = v; - foreach (ObjectBase * c, children_) - c->setScene(v); -} - - -void ObjectBase::addChild(ObjectBase * o) { - if (o == this) return; - if (o->parent_) - o->parent_->children_.removeAll(o); - children_ << o; - o->parent_ = this; - o->setScene(scene_); - o->buildTransform(); - /*if (scene_) { - ObjectBaseList cl = o->children(true); - cl << o; - //foreach (ObjectBase * i, cl) { - // emit view_->objectAdded(i); - //} - }*/ - setSceneTreeChanged(); -} - - -void ObjectBase::removeChild(ObjectBase * o) { - if (o == this) return; - children_.removeAll(o); - o->parent_ = nullptr; - o->buildTransform(); - setSceneTreeChanged(); -} - - -void ObjectBase::removeChild(int index) { - children_[index]->parent_ = nullptr; - children_[index]->buildTransform(); - children_.removeAt(index); - setSceneTreeChanged(); -} - - -void ObjectBase::clearChildren(bool deleteAll) { - foreach (ObjectBase * i, children_) { - i->scene_ = nullptr; - i->parent_ = nullptr; - i->clearChildren(deleteAll); - if (deleteAll) { - delete i; - } else { - i->buildTransform(); - } - } - children_.clear(); - setSceneTreeChanged(); -} - - -ObjectBase * ObjectBase::child(int index) { - if (index < 0 || index >= children_.size()) return nullptr; - return children_[index]; -} - - -ObjectBase * ObjectBase::child(const QString & name) { - foreach (ObjectBase * i, children_) - if (i->name_ == name) return i; - return nullptr; -} - - -const ObjectBase * ObjectBase::child(int index) const { - if (index < 0 || index >= children_.size()) return nullptr; - return children_[index]; -} - - -const ObjectBase * ObjectBase::child(const QString & name) const { - foreach (ObjectBase * i, children_) - if (i->name_ == name) return i; - return nullptr; -} - - -ObjectBaseList ObjectBase::children(bool all_) { - if (!all_) return children_; - ObjectBaseList cl; - addChildren(cl, this); - return cl; -} - - -bool ObjectBase::isVisible(bool check_parents) const { - if (!check_parents) return visible_; - if (!visible_) return false; - ObjectBase * p = parent_; - while (p) { - if (!p->visible_) return false; - p = p->parent_; - } - return true; -} - - -void ObjectBase::setVisible(bool v) { - visible_ = v; - setSceneTreeChanged(); -} - - -void ObjectBase::rotateZ(GLfloat a) { - raw_matrix = false; - trans.setRotationZ(trans.rotationZ() + a); - //angles_.setZ(angles_.z() + a); - //while (angles_.z() < -360.f) angles_.setZ(angles_.z() + 360.f); - //while (angles_.z() > 360.f) angles_.setZ(angles_.z() - 360.f); - buildTransform(); -} - - -void ObjectBase::setRotationZ(GLfloat a) { - raw_matrix = false; - trans.setRotationZ(a); - //angles_.setZ(a); - //while (angles_.z() < -360.f) angles_.setZ(angles_.z() + 360.f); - //while (angles_.z() > 360.f) angles_.setZ(angles_.z() - 360.f); - buildTransform(); -} - - -void ObjectBase::setTransform(const Transform & t) { - trans = t; - buildTransform(); -} - - -void ObjectBase::addChildren(ObjectBaseList & list, ObjectBase * where) { - foreach (ObjectBase * i, where->children_) { - list << i; - addChildren(list, i); - } -} - - -void ObjectBase::calculateBoundingBox() { - bound = Box3D(); - if (mesh_) { - bound = mesh_->boundingBox(); - QVector c = bound.corners(), tc; - foreach (QVector3D p, c) - tc << (itransform_ * QVector4D(p, 1)).toVector3D(); - bound = Box3D(tc); - } - foreach (ObjectBase * i, children_) { - i->calculateBoundingBox(); - bound |= i->boundingBox(); - } -} - - -void ObjectBase::updateTransform() { - buildTransform(true); -} - - -void ObjectBase::setProperty(const QString & pn, const QVariant & v) { - meta[pn] = v; -} - - -QVariant ObjectBase::property(const QString & pn, bool * exists) const { - if (exists) *exists = meta.contains(pn); - return meta.value(pn); -} - - -bool ObjectBase::hasProperty(const QString & pn) const { - return meta.contains(pn); -} - - -void ObjectBase::removeProperty(const QString & pn) { - meta.remove(pn); -} - - -void ObjectBase::setMatrix(const QMatrix4x4 & t) { - //raw_matrix = true; - //mat_ = t; - //pos_ = mat_.column(3).toVector3D(); - //mat_.setColumn(3, QVector4D(0., 0., 0., 1.)); - raw_matrix = false; - trans.setMatrix(t); - buildTransform(); -} - - -QMatrix4x4 ObjectBase::matrix() const { - return trans.matrix(); -} - - -QVector3D ObjectBase::inParentSpace(const QVector3D & v) const { - if (!parent_) return v; - return (parent_->matrix() * QVector4D(v, 1)).toVector3D(); -} - - -void ObjectBase::transferTransformToChildren(bool only_scale) { - QMatrix4x4 m = trans.matrix(); - if (only_scale) m = trans.matrixScale(); - foreach (ObjectBase * i, children_) - i->trans.setMatrix(m * i->trans.matrix()); - if (only_scale) resetScale(); - else setMatrix(QMatrix4x4()); -} - - -void ObjectBase::cleanTree() { - for (int i = 0; i < children_.size(); ++i) { - ObjectBase * o = children_[i]; - if (!o->hasChildren() && !o->mesh() && (o->type() == glMesh)) { - delete o; - --i; - } - o->cleanTree(); - } -} - - -bool ObjectBase::isSelected(bool check_parents) const { - if (!check_parents) return selected_; - if (selected_) return true; - ObjectBase * p = parent_; - while (p) { - if (p->selected_) return true; - p = p->parent_; - } - return false; -} - - -void ObjectBase::setSelected(bool yes) { - //qDebug() << "select" << name() << view_; - if (select_) - selected_ = yes; - if (!selected_) - selected_aim = false; -} - - -ObjectBase * ObjectBase::selectedParent() const { - ObjectBase * p = parent_; - while (p) { - if (p->selected_) return p; - p = p->parent_; - } - return 0; -} - - -void ObjectBase::setMaterial(Material * m, bool with_children) { - material_ = m; - if (with_children) - foreach (ObjectBase * i, children_) i->setMaterial(m, true); - setObjectsChanged(); - if (scene_) scene_->mat_changed = scene_->tree_changed = true; -} - - -void ObjectBase::setColor(QColor c, bool with_children) { - color_ = c; - if (with_children) - foreach (ObjectBase * i, children_) i->setColor(c, true); - setObjectsChanged(); -} - - -void ObjectBase::setMesh(Mesh * v) { - if (scene_) - v = scene_->attachMesh(v); - mesh_ = v; - setSceneTreeChanged(); - setObjectsChanged(); -} - - -void ObjectBase::buildTransform(bool force) { - if (force) trans.setDirty(); - itransform_.setToIdentity(); - ObjectBase * p = parent_; - if (p) - itransform_ = p->itransform_; - //if (raw_matrix) { - // itransform_.translate(pos_); - // itransform_ *= mat_; - // //qDebug() << "raw_matrix" << itransform_; - //} else - localTransform(itransform_); - //qDebug() << name_ << itransform_; - foreach (ObjectBase * i, children_) - i->buildTransform(force); - setObjectsChanged(); -} - - -void ObjectBase::initInternal() { - init(); - foreach (ObjectBase * i, children_) i->initInternal(); -} - - -void ObjectBase::localTransform(QMatrix4x4 & m) { - m *= trans.matrix(); -} - - -void ObjectBase::setSceneTreeChanged() { - if (scene_) { - scene_->setTreeChanged(); - scene_->setTreeStructChanged(); - } - setObjectsChanged(); -} - - -void ObjectBase::setObjectsChanged() { - int p = pass(); - if (mesh_) { - mesh_->setObjectsChanged (p, true); - mesh_->setSelectionChanged(p, true); - if (prev_pass != p) { - mesh_->setObjectsChanged (prev_pass, true); - mesh_->setSelectionChanged(prev_pass, true); - } - } - prev_pass = p; -} - - -QMatrix4x4 ObjectBase::worldMatrix(QMatrix4x4 parent) const { - QMatrix4x4 mat; - //mat.translate(pos_); - //if (raw_matrix) { - // mat *= mat_; - //} else { - // if (angles_.z() != 0.f) mat.rotate(angles_.z(), 0., 0., 1.); - // if (angles_.y() != 0.f) mat.rotate(angles_.y(), 0., 1., 0.); - // if (angles_.x() != 0.f) mat.rotate(angles_.x(), 1., 0., 0.); - // mat.scale(scale_); - //} - mat = trans.matrix(); - return parent * mat; -} - - - - -AimedObject::AimedObject() { - aim_dist = 1.; -} - - -QVector3D AimedObject::worldAim() const { - QVector3D ret = worldPos() + worldDirection() * aim_dist; - return ret; -} - - -void AimedObject::setAim(const QVector3D & p) { - QVector3D dir = p - pos(); - trans.setRotation(Transform::fromDirection(dir, trans.rotationY())); - aim_dist = dir.length(); - buildTransform(); - //if (!p.isNull()) - //qDebug() << "setAim" << p << aim() << worldAim(); -} - - -QVector3D AimedObject::direction() const { - return trans.direction(); -} - - -void AimedObject::setDirection(const QVector3D & d) { - //double len = qMax(aim_.length(), 0.001f); - //aim_ = d.normalized() * len; - buildTransform(); -} - - -void AimedObject::flyCloser(double s) { - double tl = 1. / (1. + s); - move(direction() * aim_dist * (1. - tl)); - aim_dist *= tl; -} - - -void AimedObject::flyFarer(double s) { - double tl = 1. * (1. + s); - move(direction() * aim_dist * (1. - tl)); - aim_dist *= tl; -} - - -void AimedObject::flyToDistance(double d) { - move(direction() * (aim_dist - d)); - aim_dist = d; - //qDebug() << d << (aim() - pos()).length() << aim(); -} - - -void AimedObject::moveForward(const float & x, bool withZ) { - QVector3D dv = itransform_.mapVector(QVector3D(0, 0, -x)); - if (!withZ) dv[2] = 0.; - move(dv); -} - - -void AimedObject::moveLeft(const float & x, bool withZ) { - QVector3D dv = itransform_.mapVector(QVector3D(-x, 0, 0)); - if (!withZ) dv[2] = 0.; - move(dv); -} - - -void AimedObject::moveUp(const float & x, bool onlyZ) { - QVector3D dv = itransform_.mapVector(QVector3D(0, x, 0)); - if (onlyZ) dv[0] = dv[1] = 0.; - move(dv); -} - - -void AimedObject::orbitZ(const float & a) { - QVector3D pa = aim(); - rotateZ(-a); - move(pa - aim()); -} - - -void AimedObject::orbitXY(const float & a) { - QVector3D pa = aim(); - rotateX(-a); - move(pa - aim()); -} - - -void AimedObject::transformChanged() { - -} - - - - -Light::Light(): AimedObject(), shadow_map(0, true, GL_R16F) { - type_ = glLight; - light_type = Omni; - intensity = 1.; - angle_start = angle_end = 180.; - decay_linear = decay_quadratic = decay_start = 0.; - decay_const = decay_end = 1.; - setDirection(0, 0, -1.); -} - - -Light::Light(const QVector3D & p, const QColor & c, float i): AimedObject(), shadow_map(0, true, GL_R16F) { - type_ = glLight; - light_type = Omni; - intensity = i; - color_ = c; - angle_start = angle_end = 180.; - decay_linear = decay_quadratic = decay_start = 0.; - decay_const = decay_end = 1.; - setPos(p); - setDirection(0, 0, -1.); -} - - -ObjectBase * Light::clone(bool withChildren) { - Light * o = new Light(*this); - //GLObjectBase::clone(withChildren); - o->is_init = false; - o->name_ = name_;// + "_copy"; - o->scene_ = nullptr; - o->children_.clear(); - if (withChildren) { - for (int i = 0; i < children_.size(); ++i) - o->addChild(children_[i]->clone(withChildren)); - } - o->color_ = color_; - o->light_type = light_type; - o->trans = trans; - o->aim_dist = aim_dist; - o->angle_start = angle_start; - o->angle_end = angle_end; - o->intensity = intensity; - o->decay_const = decay_const; - o->decay_linear = decay_linear; - o->decay_quadratic = decay_quadratic; - o->meta = meta; - return o; -} - - -void Light::apply() { - if (scene_) scene_->setLightsChanged(); -} - - -QDataStream & operator <<(QDataStream & s, const ObjectBase * p) { - ChunkStream cs; - //qDebug() << "place" << p->name() << "..."; - cs.add(1, int(p->type_)).add(2, p->accept_light).add(3, p->accept_fog).add(4, p->visible_) - .add(5, p->cast_shadow).add(6, p->rec_shadow).add(7, p->raw_matrix).add(8, p->line_width) - .add(9, int(p->render_mode)).add(14, p->mat_).add(16, p->children_.size()) - .add(17, p->name_).add(18, p->meta).add(19, p->color_).add(20, p->trans); - //qDebug() << "place self done"; - if (p->type_ == ObjectBase::glLight) { - //qDebug() << "place light ..."; - const Light * l = (const Light*)p; - cs.add(101, l->angle_start).add(102, l->angle_end).add(103, l->intensity) - .add(104, l->decay_const).add(105, l->decay_linear).add(106, l->decay_quadratic) - .add(107, l->decay_start).add(108, l->decay_end).add(109, int(l->light_type)) - .add(111, l->distance()); - } - if (p->type_ == ObjectBase::glCamera) { - //qDebug() << "place camera ..."; - const Camera * c = (const Camera*)p; - cs.add(200, c->aim()).add(201, c->fov_).add(202, c->depth_start) - .add(206, c->mirror_x).add(207, c->mirror_y).add(208, c->distance()) - .add(209, c->roll_); - } - //qDebug() << "place" << p->name() << cs.data().size() << s.device()->size(); - s << cs.data(); - foreach (const ObjectBase * c, p->children_) - s << c; - return s; -} -QDataStream & operator >>(QDataStream & s, ObjectBase *& p) { - ChunkStream cs(s); - p = nullptr; - int ccnt = 0; - Light * l = nullptr; - Camera * c = nullptr; - //qDebug() << "read obj ..."; - while (!cs.atEnd()) { - switch (cs.read()) { - case 1: { - ObjectBase::Type type = (ObjectBase::Type)cs.getData(); - switch (type) { - case ObjectBase::glMesh: p = new ObjectBase(); break; - case ObjectBase::glLight: p = new Light(); l = (Light*)p; break; - case ObjectBase::glCamera: p = new Camera(); c = (Camera*)p; break; - default : break; - } - if (p) p->type_ = type; - } break; - case 2: if (p) p->accept_light = cs.getData(); break; - case 3: if (p) p->accept_fog = cs.getData(); break; - case 4: if (p) p->visible_ = cs.getData(); break; - case 5: if (p) p->cast_shadow = cs.getData(); break; - case 6: if (p) p->rec_shadow = cs.getData(); break; - case 7: if (p) p->raw_matrix = cs.getData(); break; - case 8: if (p) p->line_width = cs.getData(); break; - case 9: if (p) p->render_mode = (ObjectBase::RenderMode)cs.getData(); break; - case 14: if (p) p->mat_ = cs.getData(); break; - case 16: if (p) ccnt = cs.getData(); break; - case 17: if (p) p->name_ = cs.getData(); break; - case 18: if (p) p->meta = cs.getData(); break; - case 19: if (p) p->color_ = cs.getData(); break; - case 20: if (p) p->trans = cs.getData(); break; - case 100: if (l) l->setAim(cs.getData()); break; - case 101: if (l) l->angle_start = cs.getData(); break; - case 102: if (l) l->angle_end = cs.getData(); break; - case 103: if (l) l->intensity = cs.getData(); break; - case 104: if (l) l->decay_const = cs.getData(); break; - case 105: if (l) l->decay_linear = cs.getData(); break; - case 106: if (l) l->decay_quadratic = cs.getData(); break; - case 107: if (l) l->decay_start = cs.getData(); break; - case 108: if (l) l->decay_end = cs.getData(); break; - case 109: if (l) l->light_type = (Light::Type)cs.getData(); break; - case 111: if (l) l->setDistance(cs.getData()); break; - case 200: if (c) c->setAim(cs.getData()); break; - case 201: if (c) c->setFOV(cs.getData()); break; - case 202: if (c) c->setDepthStart(cs.getData()); break; - case 206: if (c) c->mirror_x = cs.getData(); break; - case 207: if (c) c->mirror_y = cs.getData(); break; - case 208: if (c) c->setDistance(cs.getData()); break; - case 209: if (c) c->roll_ = cs.getData(); break; - } - } - //qDebug() << p->name() << ccnt; - for (int i = 0; i < ccnt; ++i) { - ObjectBase * c = nullptr; - s >> c; - if (!c) continue; - c->parent_ = p; - p->children_ << c; - } - p->buildTransform(); - return s; -} diff --git a/qglengine/globject.h b/qglengine/globject.h deleted file mode 100644 index bfd9958..0000000 --- a/qglengine/globject.h +++ /dev/null @@ -1,313 +0,0 @@ -/* - QGL ObjectBase & Light - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLOBJECT_H -#define GLOBJECT_H - -#include "glframebuffer.h" -#include "glmaterial.h" -#include "gltypes.h" -#include "gltransform.h" - - -class ObjectBase -{ - friend class QGLView; - friend class Scene; - friend class Renderer; - friend class RendererService; - friend class RendererSelection; - friend class MouseController; - friend QDataStream & operator <<(QDataStream & s, const ObjectBase * p); - friend QDataStream & operator >>(QDataStream & s, ObjectBase *& p); - friend QDataStream & operator >>(QDataStream & s, Scene *& p); -public: - enum Type {glMesh, glLight, glCamera, glParticlesSystem}; - enum RenderMode {View = 0, Point = GL_POINT, Line = GL_LINE, Fill = GL_FILL}; - - explicit ObjectBase(Mesh * geom = 0, Material * mat = 0); - virtual ~ObjectBase(); - - virtual ObjectBase * clone(bool withChildren = true); - void destroy(); - - QString name() const {return name_;} - void setName(const QString & name) {name_ = name;} - virtual void init(); - virtual void update() {} - bool isInit() const {return is_init;} - Type type() const {return type_;} - RenderPass pass() const; - - RenderMode renderMode() const {return render_mode;} - void setRenderMode(RenderMode mode) {render_mode = mode;} - - float lineWidth() const {return line_width;} - void setLineWidth(const float & width) {line_width = width;} - - ObjectBase * parent() {return parent_;} - void setParent(ObjectBase * o) {parent_ = o;} - bool hasParent() const {return parent_ != nullptr;} - bool hasChildren() const {return !children_.isEmpty();} - void setScene(Scene * v); - - void addChild(ObjectBase * o); - void removeChild(ObjectBase * o); - void removeChild(int index); - void clearChildren(bool deleteAll = false); - int childCount() const {return children_.size();} - ObjectBase * child(int index); - ObjectBase * child(const QString & name); - const ObjectBase * child(int index) const; - const ObjectBase * child(const QString & name) const; - ObjectBaseList children(bool all_ = false); - - bool isVisible(bool check_parents = false) const; - bool isHidden(bool check_parents = false) const {return !isVisible(check_parents);} - void setVisible(bool v); - void setHidden(bool v) {setVisible(!v);} - void show() {setVisible(true);} - void hide() {setVisible(false);} - - bool isReceiveShadows() const {return rec_shadow;} - bool isCastShadows() const {return cast_shadow;} - void setReceiveShadows(bool on) {rec_shadow = on;} - void setCastShadows(bool on) {cast_shadow = on;} - - void move(const QVector3D & dv) {trans.setTranslation(pos() + dv); buildTransform();} - void moveTo(const QVector3D & dv) {trans.setTranslation(dv); buildTransform();} - void move(GLfloat dx, GLfloat dy, GLfloat dz = 0.) {move(QVector3D(dx, dy, dz)); buildTransform();} - void moveTo(GLfloat dx, GLfloat dy, GLfloat dz = 0.) {moveTo(QVector3D(dx, dy, dz)); buildTransform();} - void moveX(GLfloat o) {trans.setTranslationX(posX() + o); buildTransform();} - void moveY(GLfloat o) {trans.setTranslationY(posY() + o); buildTransform();} - void moveZ(GLfloat o) {trans.setTranslationZ(posZ() + o); buildTransform();} - void setPosX(GLfloat o) {trans.setTranslationX(o); buildTransform();} - void setPosY(GLfloat o) {trans.setTranslationY(o); buildTransform();} - void setPosZ(GLfloat o) {trans.setTranslationZ(o); buildTransform();} - void setPos(GLfloat x, GLfloat y, GLfloat z) {trans.setTranslation(QVector3D(x, y, z)); buildTransform();} - void setPos(const QVector3D & p) {trans.setTranslation(p); buildTransform();} - void resetPos() {trans.setTranslation(QVector3D()); buildTransform();} - - QVector3D pos() const {return trans.translation();} - float posX() const {return trans.translation().x();} - float posY() const {return trans.translation().y();} - float posZ() const {return trans.translation().z();} - QVector3D worldPos() const {return (itransform_ * QVector4D(0, 0, 0, 1.)).toVector3D();} - QMatrix4x4 worldTransform() const {return itransform_;} - - QVector3D rotation() const {return trans.rotation();} - float rotationX() const {return rotation().x();} - float rotationY() const {return rotation().y();} - float rotationZ() const {return rotation().z();} - void rotateX(GLfloat a) {raw_matrix = false; trans.setRotationX(trans.rotationX() + a); buildTransform();} - void rotateY(GLfloat a) {raw_matrix = false; trans.setRotationY(trans.rotationY() + a); buildTransform();} - void rotateZ(GLfloat a); - void setRotationX(GLfloat a) {raw_matrix = false; trans.setRotationX(a); buildTransform();} - void setRotationY(GLfloat a) {raw_matrix = false; trans.setRotationY(a); buildTransform();} - void setRotationZ(GLfloat a); - void setRotation(const QVector3D & a) {raw_matrix = false; trans.setRotation(a); buildTransform();} - void resetRotation() {raw_matrix = false; trans.setRotation(QVector3D()); buildTransform();} - - QVector3D scale() {return trans.scale3D();} - float scaleX() {return trans.scale3D().x();} - float scaleY() {return trans.scale3D().y();} - float scaleZ() {return trans.scale3D().z();} - void scale(const QVector3D & sv) {raw_matrix = false; trans.setScale(trans.scale3D() * sv); buildTransform();} - void scale(GLfloat sx, GLfloat sy, GLfloat sz) {raw_matrix = false; scale(QVector3D(sx, sy, sz)); buildTransform();} - void scale(GLfloat sx, GLfloat sy) {raw_matrix = false; scale(QVector3D(sx, sy, sy)); buildTransform();} - void scale(GLfloat sx) {raw_matrix = false; scale(QVector3D(sx, sx, sx)); buildTransform();} - void scaleX(GLfloat a) {raw_matrix = false; trans.setScaleX(trans.scale3D().x() + a); buildTransform();} - void scaleY(GLfloat a) {raw_matrix = false; trans.setScaleY(trans.scale3D().y() + a); buildTransform();} - void scaleZ(GLfloat a) {raw_matrix = false; trans.setScaleZ(trans.scale3D().z() + a); buildTransform();} - void setScale(const QVector3D & a) {raw_matrix = false; trans.setScale(a); buildTransform();} - void setScale(GLfloat a) {raw_matrix = false; trans.setScale(a); buildTransform();} - void setScaleX(GLfloat a) {raw_matrix = false; trans.setScaleX(a); buildTransform();} - void setScaleY(GLfloat a) {raw_matrix = false; trans.setScaleY(a); buildTransform();} - void setScaleZ(GLfloat a) {raw_matrix = false; trans.setScaleZ(a); buildTransform();} - void resetScale() {raw_matrix = false; trans.setScale(1.f); buildTransform();} - - Transform transform() {return trans;} - void setTransform(const Transform & t); - void setMatrix(const QMatrix4x4 & t); - QMatrix4x4 matrix() const; - bool isRawMatrix() {return raw_matrix;} - QVector3D inParentSpace(const QVector3D & v) const; - void transferTransformToChildren(bool only_scale = false); - void cleanTree(); - - bool isAcceptLight() const {return accept_light;} - void setAcceptLight(bool yes) {accept_light = yes;} - - bool isAcceptFog() const {return accept_fog;} - void setAcceptFog(bool yes) {accept_fog = yes;} - - bool isSelected(bool check_parents = false) const; - void setSelected(bool yes); - void select() {setSelected(true);} - void deselect() {setSelected(false);} - ObjectBase * selectedParent() const; - - bool isSelectable() const {return select_;} - void setSelectable(bool yes) {select_ = yes;} - /* - bool isWriteDepth() const {return write_depth_;} - void setWriteDepth(bool yes) {write_depth_ = yes;}*/ - - GLenum srcAlpha() const {return blend_src;} - GLenum destAlpha() const {return blend_dest;} - void setSrcAlpha(GLenum mode) {blend_src = mode;} - void setDestAlpha(GLenum mode) {blend_dest = mode;} - - void setMaterial(Material * m, bool with_children = false); - Material * material() {return material_;} - - void setColor(QColor c, bool with_children = false); - QColor color() {return color_;} - - const Box3D & boundingBox() const {return bound;} - void setMesh(Mesh * v); - Mesh * mesh() {return mesh_;} - - void calculateBoundingBox(); - void updateTransform(); - - void setProperty(const QString & pn, const QVariant & v); - QVariant property(const QString & pn, bool * exists = 0) const; - bool hasProperty(const QString & pn) const; - void removeProperty(const QString & pn); - - QVector3D pos_h; - - //QVector d_vertices, d_normals, d_uvs; - -protected: - virtual void transformChanged() {} - void addChildren(ObjectBaseList & list, ObjectBase * where); - void buildTransform(bool force = false); - void initInternal(); - void setSceneTreeChanged(); - void setObjectsChanged(); - void localTransform(QMatrix4x4 & m); - QMatrix4x4 worldMatrix(QMatrix4x4 parent) const; - - int prev_pass; // Pass - bool is_init, accept_light, accept_fog, visible_, cast_shadow, rec_shadow, select_, selected_, raw_matrix; - bool is_root, selected_aim; - float line_width; - QColor color_; - uint id_; - Type type_; - RenderMode render_mode; - Box3D bound; - Transform trans; - ObjectBaseList children_; - QMatrix4x4 itransform_, mat_; - QString name_; - GLenum blend_src, blend_dest; - ObjectBase * parent_; - Scene * scene_; - Material * material_; - Mesh * mesh_; - QVariantMap meta; - -}; - -inline bool operator <(const ObjectBase & f, const ObjectBase & s) {return f.pos_h.z() < s.pos_h.z();} - - -class AimedObject: public ObjectBase { - friend class QGLView; - friend class GLRendererBase; - friend class Light; - friend class Camera; -public: - AimedObject(); - ~AimedObject() {} - QVector3D aim() const {return pos() + (direction() * aim_dist);} - QVector3D worldAim() const; - void setAim(const QVector3D & p); - QVector3D direction() const; - QVector3D worldDirection() const {return (itransform_ * QVector4D(QVector3D(0,0,-1), 0.)).toVector3D().normalized();} - void setDirection(const QVector3D & d); - void setDirection(double x, double y, double z) {setDirection(QVector3D(x, y, z));} - - double distance() const {return aim_dist;} - void setDistance(double d) {aim_dist = d;} - void flyCloser(double s); - void flyFarer(double s); - void flyToDistance(double d); - - void moveForward(const float & x, bool withZ = true); - void moveBackward(const float & x, bool withZ = true) {moveForward(-x, withZ);} - void moveLeft(const float & x, bool withZ = true); - void moveRight(const float & x, bool withZ = true) {moveLeft(-x, withZ);} - void moveUp(const float & x, bool onlyZ = false); - void moveDown(const float & x, bool onlyZ = false) {moveUp(-x, onlyZ);} - - void rotateRoll(const float & a) {rotateY(a);} - void orbitZ(const float & a); - void orbitXY(const float & a); - -protected: - void transformChanged() override; - double aim_dist; -}; - - -class Light: public AimedObject { - friend class QGLView; - friend class RendererBase; -public: - enum Type {Omni, Cone, Directional}; - - Light(); - Light(const QVector3D & p, const QColor & c = Qt::white, float i = 1.); - virtual ObjectBase * clone(bool withChildren = true); - virtual void init() {shadow_map.resize(512, 512); is_init = true;} - void apply(); - - float angle_start; - float angle_end; - float intensity; - float decay_const; - float decay_linear; - float decay_quadratic; - float decay_start; - float decay_end; - Type light_type; - Framebuffer shadow_map; - QMatrix4x4 shadow_matrix; - -protected: - -}; - -template -inline T globject_cast(ObjectBase * object) {return reinterpret_cast(object);} - -template -inline T globject_cast(const ObjectBase * object) {return reinterpret_cast(object);} - - -QDataStream & operator <<(QDataStream & s, const ObjectBase * p); -QDataStream & operator >>(QDataStream & s, ObjectBase *& p); - -inline ObjectBaseList lights2objectList(const QList & v) {ObjectBaseList ret; foreach (Light*i, v) ret << (ObjectBase*)i; return ret;} -inline ObjectBaseList cameras2objectList(const QList & v) {ObjectBaseList ret; foreach (Camera*i, v) ret << (ObjectBase*)i; return ret;} - -#endif // GLOBJECT_H diff --git a/qglengine/glrendererbase.cpp b/qglengine/glrendererbase.cpp deleted file mode 100644 index edb92b6..0000000 --- a/qglengine/glrendererbase.cpp +++ /dev/null @@ -1,294 +0,0 @@ -/* - QGL GLRendererBase - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "glrendererbase.h" -#include "globject.h" -#include "qglview.h" - - -GLRendererBase::GLRendererBase(QGLView * view_): view(view_) { - white_image = QImage(1, 1, QImage::Format_ARGB32); - white_image.fill(0xFFFFFFFF); - white_image_id = 0; - violent_image = QImage(1, 1, QImage::Format_ARGB32); - violent_image.fill(QColor(127, 127, 255)); - violent_image_id = 0; -} - - -void GLRendererBase::setupLight(const Light & l, int inpass_index, int gl_index) { - QVector3D lp = l.worldPos(), ld;// = (l.itransform_ * QVector4D(l.direction, 0.)).toVector3D().normalized(); - GLfloat pos[] = {0.f, 0.f, 0.f, 0.f}; - GLfloat dir[] = {0.f, 0.f, 0.f}; - GLfloat col[] = {0.f, 0.f, 0.f}; - pos[0] = l.light_type == Light::Directional ? -l.direction().x() : lp.x(); - pos[1] = l.light_type == Light::Directional ? -l.direction().y() : lp.y(); - pos[2] = l.light_type == Light::Directional ? -l.direction().z() : lp.z(); - pos[3] = l.light_type == Light::Directional ? 0. : 1.; - dir[0] = ld.x(); - dir[1] = ld.y(); - dir[2] = ld.z(); - //col[0] = l.visible_ ? l.color().redF() * l.intensity : 0.f; - //col[1] = l.visible_ ? l.color().greenF() * l.intensity : 0.f; - //col[2] = l.visible_ ? l.color().blueF() * l.intensity : 0.f; - glEnable(gl_index); - //glLightfv(gl_index, GL_AMBIENT, ambient); - glLightfv(gl_index, GL_DIFFUSE, col); - glLightfv(gl_index, GL_SPECULAR, col); - glLightfv(gl_index, GL_POSITION, pos); - glLightf(gl_index, GL_CONSTANT_ATTENUATION, l.decay_const); - glLightf(gl_index, GL_LINEAR_ATTENUATION, l.decay_linear); - glLightf(gl_index, GL_QUADRATIC_ATTENUATION, l.decay_quadratic); - if (l.light_type == Light::Cone) { - glLightfv(gl_index, GL_SPOT_DIRECTION, dir); - glLightf(gl_index, GL_SPOT_CUTOFF, l.angle_end / 2.f); - glLightf(gl_index, GL_SPOT_EXPONENT, (1.f - piClamp((l.angle_end - l.angle_start) / (l.angle_end + 0.001f), 0., 1.f)) * 128.f); - } else { - glLightf(gl_index, GL_SPOT_CUTOFF, 180.); - } - -} - - -void GLRendererBase::setupAmbientLight(const QColor & a, bool first_pass) { - GLfloat ambient[] = {0.0f, 0.0f, 0.0f, 1.f}; - if (first_pass) { - ambient[0] = view->ambientColor_.redF(); - ambient[1] = view->ambientColor_.greenF(); - ambient[2] = view->ambientColor_.blueF(); - } - glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); -} - - -void GLRendererBase::setupShadersLights(int lights_count) { - /*foreach (QOpenGLShaderProgram * i, view->shaders_ppl) { - i->bind(); - i->setUniformValue("lightsCount", lights_count); - i->setUniformValue("acc_light", lights_count > 0); - //i->setUniformValue("mat", mvm); - }*/ -} - - -#define BIND_TEXTURE(ch, map) if (rp.prev_tex[ch] != mat.map.bitmap_id) { \ - rp.prev_tex[ch] = mat.map.bitmap_id; \ - glActiveTexture(GL_TEXTURE0 + ch); glBindTexture(GL_TEXTURE_2D, mat.map.bitmap_id); \ - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, view->feature(QGLView::qglAnisotropicLevel).toInt());} - -void GLRendererBase::setupTextures(ObjectBase & o, GLRendererBase::RenderingParameters & rp, bool first_object) { -} - -#undef BIND_TEXTURE - - -void GLRendererBase::setupLights(int pass, int lights_per_pass) { - /*int light_start, light_end, lmax; - light_start = pass * lights_per_pass; - light_end = qMin((pass + 1) * lights_per_pass, view->lights_.size()); - setupAmbientLight(view->ambientColor_, pass == 0); - if (!view->lights_.isEmpty()) { - setupShadersLights(light_end - light_start); - for (int i = light_start; i < light_end; ++i) - setupLight(*view->lights_[i], i - light_start, GL_LIGHT0 + i - light_start); - lmax = light_start + 8; - for (int i = light_end; i < lmax; ++i) - glDisable(GL_LIGHT0 + i - light_start); - } else { - setupShadersLights(0); - for (int i = 0; i < 8; ++i) - glDisable(GL_LIGHT0 + i); - }*/ -} - - -void GLRendererBase::applyFilteringParameters() { - /*if (view->isFeatureEnabled(QGLView::qglLinearFiltering)) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - } else { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); - }*/ - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, view->feature(QGLView::qglAnisotropicLevel).toInt()); -} - - -void GLRendererBase::renderObjects(int pass, int light_pass, void * shaders, bool textures, bool light, bool fog) { - /*RenderingParameters rpl; - rpl.pass = pass; - rpl.light_pass = light_pass; - rpl.shaders = shaders; - rpl.textures = textures; - rpl.light = rpl.prev_light = light; - rpl.fog = rpl.prev_fog = fog; - rpl.view_matrix = rp.view_matrix; - rpl.prev_view_matrix = rp.prev_view_matrix; - rpl.proj_matrix = rp.proj_matrix; - rpl.prev_proj_matrix = rp.prev_proj_matrix; - rpl.cam_offset_matrix = view->camera()->offsetMatrix(); - //qDebug() << "view:" << rp.view_matrix; - for (int i = 0; i < 32; ++i) rpl.prev_tex[i] = 0; - setupTextures(view->objects_, rpl, true); - glSetCapEnabled(GL_TEXTURE_2D, rpl.textures); - glSetCapEnabled(GL_BLEND, pass == ObjectBase::Transparent); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDisable(GL_TEXTURE_CUBE_MAP); - glPushMatrix(); - renderSingleObject(view->objects_, rpl); - glPopMatrix();*/ -} - - -void GLRendererBase::renderSingleObject(ObjectBase & o, RenderingParameters & rpl) { -// if (!o.isInit()) -// o.init(); -// if (!o.isTexturesLoaded()) -// o.loadTextures(); -// if (!o.visible_) return; -// if (rpl.pass == o.pass_) { -// //Material & mat(o.material_); -// QMatrix4x4 curview = rpl.view_matrix * rpl.cam_offset_matrix * o.itransform_, prevview = rpl.prev_view_matrix * rpl.cam_offset_matrix * o.itransform_; -// //setupTextures(o, rpl, false); -// //mat.apply((QOpenGLShaderProgram*)rpl.shaders); -// glSetPolygonMode(o.render_mode != ObjectBase::View ? o.render_mode : (view->rmode != ObjectBase::View ? view->rmode : GL_FILL)); -// glLineWidth(o.line_width > 0.f ? o.line_width : view->lineWidth_); -// glPointSize(o.line_width > 0.f ? o.line_width : view->lineWidth_); -// o.update(); -// /*if (o.pass_ == GLObjectBase::Transparent) { -// glActiveTexture(GL_TEXTURE0 + 3); -// if (mat.reflectivity > 0.f) { -// glEnable(GL_TEXTURE_CUBE_MAP); -// //if (!mat.map_reflection.isEmpty()) mat.map_reflection.bind(); -// //else glDisable(GL_TEXTURE_CUBE_MAP); -// } else glDisable(GL_TEXTURE_CUBE_MAP); -// if (rpl.light_pass > 0) glDisable(GL_TEXTURE_CUBE_MAP); -// GLfloat gm[16], bc[4] = {mat.reflectivity, mat.reflectivity, mat.reflectivity, mat.reflectivity}; -// glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); -// glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE); -// glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT); -// glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR); -// glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, bc); -// glGetFloatv(GL_MODELVIEW_MATRIX, gm); -// glMatrixMode(GL_TEXTURE); -// ///glLoadTransposeMatrixf(gm); -// glScalef(-1., -1., -1.); -// glMatrixMode(GL_MODELVIEW); -// glActiveTexture(GL_TEXTURE0); -// }*/ -// if (rpl.shaders) { -// //qDebug() << o.name() << curview << curview->determinant(); -// //setUniformMatrices((QOpenGLShaderProgram*)rpl.shaders, rpl.proj_matrix, curview, rpl.prev_proj_matrix, prevview); -// } else { -// glMatrixMode(GL_MODELVIEW); -// //setGLMatrix(curview); -// } -// o.draw((QOpenGLShaderProgram*)rpl.shaders); -// } -// foreach (ObjectBase * i, o.children_) -// renderSingleObject(*i, rpl); -} - - -void GLRendererBase::renderShadow(Light * l, QOpenGLShaderProgram * prog, QMatrix4x4 mat) { - Camera cam; - QVector3D wp = l->worldPos(); - cam.setPos(wp); - cam.setAim(wp + (l->worldTransform() * QVector4D(l->direction())).toVector3D()); - cam.setDepthStart(view->camera()->depthStart()); - cam.setFOV(l->angle_end); - //cam.apply(1.); - /*cam.rotateXY(l->angle_end); - QVector3D rdir = l->direction * cos(l->angle_end / 2. * deg2rad); - l->dir0 = cam.direction() - rdir; - cam.rotateXY(-l->angle_end); - cam.rotateZ(l->angle_end); - l->dir1 = cam.direction() - rdir;*/ - //qDebug() << rdir << l->dir0 << l->dir1; - RenderingParameters rpl; - rpl.shaders = prog; - rpl.textures = rpl.light = rpl.fog = false; - //rpl.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX); - //rpl.proj_matrix = getGLMatrix(GL_PROJECTION_MATRIX); - rpl.cam_offset_matrix = cam.offsetMatrix(); - QMatrix4x4 mbias; - mbias.scale(0.5, 0.5, 0.5); - mbias.translate(1., 1., 1.); - l->shadow_matrix = mbias*rpl.proj_matrix*rpl.view_matrix*rpl.cam_offset_matrix*mat;//;// * mbias; - //qDebug() << mbias; - //glPushMatrix(); - //renderSingleShadow(view->objects_, rpl); - //glPopMatrix(); -} - - -void GLRendererBase::renderSingleShadow(ObjectBase & o, RenderingParameters & rpl) { -// if (!o.isInit()) -// o.init(); -// if (!o.visible_) return; -// if (rpl.shaders) { -// //qDebug() << o.name() << curview << curview->determinant(); -// //setUniformMatrices((QOpenGLShaderProgram*)rpl.shaders, rpl.proj_matrix, rpl.view_matrix * rpl.cam_offset_matrix * o.itransform_); -// } else { -// glMatrixMode(GL_MODELVIEW); -// //setGLMatrix(rpl.view_matrix * rpl.cam_offset_matrix * o.itransform_); -// } -// glPolygonMode(GL_FRONT_AND_BACK, o.render_mode != ObjectBase::View ? o.render_mode : (view->rmode != ObjectBase::View ? view->rmode : GL_FILL)); -// glLineWidth(o.line_width > 0.f ? o.line_width : view->lineWidth_); -// glPointSize(o.line_width > 0.f ? o.line_width : view->lineWidth_); -// o.draw((QOpenGLShaderProgram*)rpl.shaders, true); -// foreach (ObjectBase * i, o.children_) -// renderSingleShadow(*i, rpl); -} - - - - -GLRendererBase::RenderingParameters::RenderingParameters() { - shaders = nullptr; - cur_shader = nullptr; -} - - -void GLRendererBase::RenderingParameters::prepare() { - //proj_matrix = getGLMatrix(GL_PROJECTION_MATRIX); - //view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX); - viewproj_matrix = proj_matrix * view_matrix; - normal_matrix = view_matrix.normalMatrix(); - proj_matrix_i = proj_matrix.inverted(); - view_matrix_i = view_matrix.inverted(); - viewproj_matrix_i = viewproj_matrix.inverted(); -} - - -void GLRendererBase::RenderingParameters::setUniform(QOpenGLShaderProgram * prog) { - if (!prog) return; - prog->setUniformValue("qgl_ModelViewMatrix", view_matrix); - prog->setUniformValue("qgl_ProjectionMatrix", proj_matrix); - prog->setUniformValue("qgl_ModelViewProjectionMatrix", viewproj_matrix); - prog->setUniformValue("qgl_NormalMatrix", normal_matrix); - prog->setUniformValue("qgl_ModelViewMatrixInverse", view_matrix_i); - prog->setUniformValue("qgl_ProjectionMatrixInverse", proj_matrix_i); - prog->setUniformValue("qgl_ModelViewProjectionMatrixInverse", viewproj_matrix_i); - prog->setUniformValue("qgl_ModelViewMatrixTranspose", view_matrix.transposed()); - prog->setUniformValue("qgl_ProjectionMatrixTranspose", proj_matrix.transposed()); - prog->setUniformValue("qgl_ModelViewProjectionMatrixTranspose", viewproj_matrix.transposed()); - prog->setUniformValue("qgl_ModelViewMatrixInverseTranspose", view_matrix_i.transposed()); - prog->setUniformValue("qgl_ProjectionMatrixInverseTranspose", proj_matrix_i.transposed()); - prog->setUniformValue("qgl_ModelViewProjectionMatrixInverseTranspose", viewproj_matrix_i.transposed()); -} diff --git a/qglengine/glrendererbase.h b/qglengine/glrendererbase.h deleted file mode 100644 index 7076d7a..0000000 --- a/qglengine/glrendererbase.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - QGL GLRendererBase - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLRENDERERBASE_H -#define GLRENDERERBASE_H - -#include "glcamera.h" -#include "glshaders.h" - -class GLRendererBase: public QObject , protected QOpenGLExtraFunctions -{ - friend class QGLView; - Q_OBJECT -public: - GLRendererBase(QGLView * view_); - virtual void prepareScene() {;} - virtual void renderScene() = 0; - - struct RenderingParameters { - RenderingParameters(); - void prepare(); - void setUniform(QOpenGLShaderProgram * prog); - int pass; - int light_pass; - bool light; - bool fog; - bool textures; - bool prev_light; - bool prev_fog; - GLuint prev_tex[32]; - void * shaders; - QMatrix4x4 view_matrix, view_matrix_i, prev_view_matrix; - QMatrix4x4 proj_matrix, proj_matrix_i, prev_proj_matrix; - QMatrix4x4 viewproj_matrix, viewproj_matrix_i; - QMatrix3x3 normal_matrix; - QMatrix4x4 cam_offset_matrix; - QOpenGLShaderProgram * cur_shader; - }; - - RenderingParameters rp; - -protected: - virtual void setupLight(const Light & l, int inpass_index, int gl_index); - virtual void setupAmbientLight(const QColor & a, bool first_pass); - virtual void setupShadersLights(int lights_count); - virtual void setupTextures(ObjectBase & object, GLRendererBase::RenderingParameters & rp, bool first_object = false); - virtual void setupShadersTextures(ObjectBase & object, GLRendererBase::RenderingParameters & rp) {} - virtual void reloadShaders() {} - virtual void init(int width, int height) {} - virtual void resize(int width, int height) {} - - void setupLights(int pass, int lights_per_pass); - inline void applyFilteringParameters(); - void renderObjects(int pass, int light_pass, void * shaders = 0, bool textures = true, bool light = true, bool fog = true); - void renderSingleObject(ObjectBase & o, RenderingParameters & rpl); - void renderShadow(Light * l, QOpenGLShaderProgram * prog = 0, QMatrix4x4 mat = QMatrix4x4()); - void renderSingleShadow(ObjectBase & o, RenderingParameters & rpl); - - QGLView * view; - QImage white_image, violent_image; - GLuint white_image_id, violent_image_id; - -}; - -#endif // GLRENDERERBASE_H diff --git a/qglengine/glscene.cpp b/qglengine/glscene.cpp deleted file mode 100644 index 1f51bc7..0000000 --- a/qglengine/glscene.cpp +++ /dev/null @@ -1,540 +0,0 @@ -/* - QGL Scene - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "glscene.h" -#include "glcamera.h" -#include "glmesh.h" -#include "qglview.h" -#include - - -Scene::Scene() { - root_ = new ObjectBase(); - root_->setScene(this); - tree_changed = mat_changed = lights_changed = true; - destroying = false; - need_reload_materials = tree_struct_changed = true; - sel_mode_ = smSingleSelection; -} - - -Scene::~Scene() { - destroying = true; - clear(); - delete root_; -} - - -Scene * Scene::clone() { - Scene * ret = new Scene(); - ObjectBase * o = root_->clone(); - foreach (ObjectBase * co, o->children()) - ret->addObject(co); - o->clearChildren(); - delete o; - return ret; -} - - -void Scene::addObject(ObjectBase * o) { - ObjectBaseList aol = o->children(true); - attachObject(o); - foreach (ObjectBase * c, aol) - attachObject(c); - root_->addChild(o); - tree_changed = tree_struct_changed = true; -} - - -void Scene::addScene(const Scene * s) { - if (!s) return; - //qDebug() << "addScene clone ..."; - ObjectBase * o = s->root_->clone(); - o->setName(s->name()); - //qDebug() << "addScene clone ok" << o << o->children(true).size(); - addObject(o); - makeMaterialsUniqueNames(); - //qDebug() << "addScene add ok" << o; -} - - -void Scene::assignFrom(const Scene * s) { - clear(); - setName(s->name()); - foreach (Material * m, s->materials) { - Material * nm = new Material(); - *nm = *m; - nm->_changed = true; - nm->setMapsChanged(); - materials << nm; - } - for (int i = 0; i < s->root_->childCount(); ++i) { - addObject(s->root_->child(i)->clone()); - //qDebug() << i << o->child(i)->pos(); - } - tree_changed = mat_changed = lights_changed = need_reload_materials = tree_struct_changed = true; -} - - -void Scene::clear() { - selected_.clear(); - selected_top.clear(); - emitSelectionChanged(); - root_->clearChildren(true); - td_geometries << geometries; - qDeleteAll(materials); - geometries.clear(); - materials.clear(); - emit __destroyed(); - emit treeChanged();} - - -void Scene::objectsCountInternal(int * cnt, ObjectBase * where) { - ++(*cnt); - foreach (ObjectBase * i, where->children_) - objectsCountInternal(cnt, i); -} -int Scene::objectsCount(bool all) { - if (!all) return root_->childCount(); - int cnt = 0; - objectsCountInternal(&cnt, root_); - return cnt; -} - - -void Scene::removeObjectInternal(ObjectBase * o, ObjectBase * where) { - if (destroying) return; - foreach (ObjectBase * i, where->children_) { - if (o == i) { - where->removeChild(i); - setObjectMeshChanged(i); - } else - removeObjectInternal(o, i); - } -} - - -void Scene::emitSelectionChanged() { - selected_top.clear(); - foreach (ObjectBase * o, selected_) { - ObjectBase * po = o->selectedParent(); - if (!po) po = o; - if (!selected_top.contains(po)) - selected_top << po; - } - foreach (Mesh * m, geometries) - m->setAllSelectionChanged(true); - selectionChanged(); -} - - -QString Scene::uniqueName(QString n, const QSet & names) { - if (!names.contains(n)) - return n; - QString num; - while (!n.isEmpty()) { - if (n.right(1)[0].isDigit()) { - num.push_front(n.right(1)); - n.chop(1); - } else break; - } - if (!n.endsWith('_')) n += '_'; - int in = num.toInt() + 1; - QString nn = n + QString::number(in).rightJustified(3, '0'); - while (names.contains(nn)) - nn = n + QString::number(++in).rightJustified(3, '0'); - return nn; -} - - - -void Scene::removeObject(ObjectBase * o, bool inChildren) { - if (destroying) return; - o->setScene(nullptr); - setObjectMeshChanged(o); - if (inChildren) - removeObjectInternal(o, root_); - else - root_->removeChild(o); - __objectDeleted(o); - setTreeStructChanged(); -} - - -void Scene::removeObject(ObjectBase & o, bool inChildren) { - if (destroying) return; - removeObject(&o, inChildren); -} - - -void Scene::clearObjects(bool deleteAll) { - root_->clearChildren(deleteAll); - cleanUnused(); - setTreeStructChanged(); - emitSelectionChanged(); -} - - -void Scene::selectObject(ObjectBase * o, bool add_to_selection) { - //qDebug() << "selectObject" << o << add_to_selection; - if (!add_to_selection || (sel_mode_ == smSingleSelection)) clearSelection(); - if (o) { - if (!add_to_selection) o->setSelected(true); - else o->setSelected(!o->isSelected()); - gatherSelection(); - } - emitSelectionChanged(); -} - - -void Scene::selectObjects(ObjectBaseList ol, bool add_to_selection) { - if (!add_to_selection || (sel_mode_ == smSingleSelection)) clearSelection(); - foreach (ObjectBase * o, ol) { - if (!o) continue; - o->setSelected(true); - } - gatherSelection(); - emitSelectionChanged(); -} - - -void Scene::selectObjectsByMesh() { - ObjectBaseList csl = selected_; - QSet sml; - foreach (ObjectBase * o, csl) - if (o->mesh()) - sml << o->mesh(); - ObjectBaseList ol = root_->children(true); - foreach (ObjectBase * o, ol) { - if (sml.contains(o->mesh())) - o->setSelected(true); - } - gatherSelection(); - emitSelectionChanged(); -} - - -void Scene::selectObjectsByMaterial() { - ObjectBaseList csl = selected_; - QSet sml; - foreach (ObjectBase * o, csl) - if (o->material()) - sml << o->material(); - ObjectBaseList ol = root_->children(true); - foreach (ObjectBase * o, ol) { - if (sml.contains(o->material())) - o->setSelected(true); - } - gatherSelection(); - emitSelectionChanged(); -} - - -void Scene::clearSelection() { - selected_.clear(); - selected_top.clear(); - ObjectBaseList ol = root_->children(true); - foreach (ObjectBase * o, ol) { - o->selected_ = o->selected_aim = false; - } - emitSelectionChanged(); -} - - -ObjectBaseList Scene::selectedObjects(bool top_only) const { - return top_only ? selected_top : selected_; -} - - -ObjectBase * Scene::selectedObject() const { - if (selected_.isEmpty()) return 0; - return selected_[0]; -} - - -void gatherMeshes(ObjectBase * o, QSet & ums) { - if (o->mesh()) ums << o->mesh(); - for (int i = 0; i < o->childCount(); ++i) - gatherMeshes(o->child(i), ums); -} -void Scene::cleanUnused() { - QSet ums; - gatherMeshes(root_, ums); - /*QMapIterator> it(geometries_used); - while (it.hasNext()) - ums |= it.next().value().keys().toSet();*/ - for (int i = 0; i < geometries.size(); ++i) { - if (ums.contains(geometries[i])) continue; - td_geometries << geometries[i]; - geometries.removeAt(i); - --i; - } -} - - -const Box3D & Scene::boundingBox() const { - root_->calculateBoundingBox(); - return root_->boundingBox(); -} - - -Material * Scene::newMaterial(const QString & name) { - materials << new Material(name); - makeMaterialsUniqueNames(); - mat_changed = true; - return materials.back(); -} - - -void Scene::removeMaterial(Material * m) { - if (!m || !materials.contains(m)) return; - ObjectBaseList ol = root_->children(true); - foreach (ObjectBase * o, ol) - if (o->material_ == m) - o->setMaterial(0); - materials.removeAll(m); - changed_materials.removeAll(m); - mat_changed = true; -} - - -void Scene::makeMaterialsUniqueNames() { - QSet names; - foreach (Material * m, materials) { - if (m->name.isEmpty()) m->name = "default_000"; - m->name = uniqueName(m->name, names); - names << m->name; - } -} - - -ObjectBaseList Scene::objects(bool all) { - return root_->children(all); -} - - -void Scene::removeLight(Light * l) { - removeObject(l); -} - - -void Scene::dump() { - qDebug() << "Scene" << name(); - qDebug() << "Meshes:" << geometries.size(); - qDebug() << "Objects:" << root_->children(true).size(); -} - - -void Scene::gatherSelection() { - selected_.clear(); - ObjectBaseList ol = root_->children(true); - foreach (ObjectBase * o, ol) - if (o->selected_) - selected_ << o; -} - - -void Scene::attachObject(ObjectBase * o) { - if (!o) return; - o->setScene(this); - if (o->mesh()) { // search suitable mesh in this scene - o->mesh_ = attachMesh(o->mesh()); - setObjectMeshChanged(o); - } - if (o->material()) { // search suitable material in this scene - uint ohash = o->material()->hash(); - bool need_new = true; - foreach (Material * m, materials) { - if (m == o->material()) { // already exists by ptr - need_new = false; - break; - } - if (m->hash() == ohash) { // already exists by hash - need_new = false; - o->setMaterial(m); - break; - } - } - if (need_new) { // need to clone material and add to scene - Material * nmat = new Material(); - *nmat = *(o->material()); - nmat->setMapsChanged(); - o->setMaterial(nmat); - materials << nmat; - } - } - setTreeStructChanged(); -} - - -Mesh * Scene::attachMesh(Mesh * mesh) { - if (!mesh) return 0; - uint mhash = mesh->hash(); - foreach (Mesh * m, geometries) { - if (m == mesh) { // already exists by ptr - return m; - } - if (m->hash() == mhash) { // already exists by hash - return m; - } - } - // need to clone mesh and add to scene - Mesh * nmesh = mesh->clone(); - geometries << nmesh; - return nmesh; -} - - -void Scene::setTreeChanged() { - if (destroying) return; - tree_changed = true; - foreach (Mesh * m, geometries) { - m->setAllObjectsChanged(true); - m->setAllSelectionChanged(true); - } - gatherSelection(); -} - - -void Scene::setTreeStructChanged() { - tree_struct_changed = true; -} - - -void Scene::setObjectMeshChanged(ObjectBase * o) { - if (o) o->setObjectsChanged(); -} - - -void Scene::prepareTree(ObjectBase * o) { - foreach (ObjectBase * co, o->children_) { - if (co->isHidden()) continue; - switch (co->type_) { - case ObjectBase::glLight: { - Light * l = globject_cast(co); - lights_used[l->light_type] << l; - } break; - case ObjectBase::glMesh: - if (co->mesh()) { - geometries_used[co->pass()][co->mesh()] << co; - co->setObjectsChanged(); - } - break; - case ObjectBase::glCamera: - cameras_used << globject_cast(co); - break; - default: break; - } - prepareTree(co); - } -} - - -bool Scene::prepare() { - changed_materials.clear(); - foreach (Material * m, materials) { - if (m->_changed) { - need_reload_materials = tree_changed = true; - changed_materials << m; - } - } - - ObjectBaseList aol; - if (!tree_changed && !mat_changed) return false; - aol = root_->children(true); - if (tree_changed) { - geometries_used[rpSolid ].clear(); - geometries_used[rpTransparent].clear(); - lights_used.clear(); - cameras_used.clear(); - prepareTree(root_); - if (tree_struct_changed) { - tree_struct_changed = false; - cleanUnused(); - QMetaObject::invokeMethod(this, "treeChanged", Qt::QueuedConnection); - } - tree_changed = false; - lights_changed = true; - } - mat_changed = false; - return true; -} - - -void Scene::destroy(QOpenGLExtraFunctions * f) { - foreach (Mesh * g, geometries) - g->destroy(f); -} - - -void Scene::destroyUnused(QOpenGLExtraFunctions * f) { - //if (!td_geometries.isEmpty()) qDebug() << "destroyUnused" << td_geometries.size(); - foreach (Mesh * i, td_geometries) - i->destroy(f); - qDeleteAll(td_geometries); - td_geometries.clear(); -} - - -QDataStream & operator <<(QDataStream & s, const Scene * p) { - ChunkStream cs; - //qDebug() << "place" << p->name() << "..."; - QVector geom_ind, mat_ind; - ObjectBaseList cl = p->root_->children(true); - geom_ind.reserve(cl.size()); - mat_ind.reserve(cl.size()); - foreach (ObjectBase * c, cl) { - geom_ind << p->geometries.indexOf(c->mesh()); - mat_ind << p->materials.indexOf(c->material()); - } - cs.add(1, p->name_).add(10, p->geometries).add(11, p->materials) - .add(20, p->root_).add(21, geom_ind).add(22, mat_ind); - s << qCompress(cs.data()); - //s << cs.data(); - return s; -} -QDataStream & operator >>(QDataStream & s, Scene *& p) { - p = new Scene(); - //ChunkStream cs(s); - - QByteArray ba; - s >> ba; - ba = qUncompress(ba); - ChunkStream cs(ba); - - QVector geom_ind, mat_ind; - while (!cs.atEnd()) { - switch (cs.read()) { - case 1 : cs.get(p->name_); break; - case 10: cs.get(p->geometries); break; - case 11: cs.get(p->materials); break; - case 20: cs.get(p->root_); p->root_->setScene(p); break; - case 21: cs.get(geom_ind); break; - case 22: cs.get(mat_ind); break; - } - } - p->makeMaterialsUniqueNames(); - ObjectBaseList cl = p->root_->children(true); - int cnt = qMin(qMin(cl.size(), geom_ind.size()), mat_ind.size()); - for (int i = 0; i < cnt; ++i) { - ObjectBase * c(cl[i]); - if (geom_ind[i] >= 0) c->mesh_ = p->geometries[geom_ind[i]]; - if (mat_ind [i] >= 0) c->material_ = p->materials [mat_ind [i]]; - } - return s; -} diff --git a/qglengine/glscene.h b/qglengine/glscene.h deleted file mode 100644 index e9e39c8..0000000 --- a/qglengine/glscene.h +++ /dev/null @@ -1,146 +0,0 @@ -/* - QGL Scene - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLSCENE_H -#define GLSCENE_H - -#include "gltypes.h" - - -class Scene: public QObject { - Q_OBJECT - friend class QGLView; - friend class RendererBase; - friend class Renderer; - friend class RendererMaterial; - friend class RendererService; - friend class RendererSelection; - friend class ObjectBase; - friend class Light; - friend QDataStream & operator <<(QDataStream & s, const Scene * p); - friend QDataStream & operator >>(QDataStream & s, Scene *& p); -public: - explicit Scene(); - virtual ~Scene(); - - enum SelectionMode { - smNoSelection, - smSingleSelection, - smMultiSelection, - }; - - Q_ENUMS(SelectionMode) - - QString name() const {return name_;} - void setName(const QString & name) {name_ = name;} - - bool prepare(); - - Scene * clone(); - - /// Add object \"o\" to scene and take its ownership - /// All materials and geometries used by \"o\" tree - /// copied into this scene - void addObject(ObjectBase * o); - - void addScene(const Scene * s); - void assignFrom(const Scene * s); - void clear(); - - int objectsCount(bool all = false); - ObjectBaseList objects(bool all = false); - ObjectBase * rootObject() {return root_;} - void removeObject(ObjectBase * o, bool inChildren = true); - void removeObject(ObjectBase & o, bool inChildren = true); - void clearObjects(bool deleteAll = false); - - SelectionMode selectionMode() const {return sel_mode_;} - void setSelectionMode(SelectionMode mode) {sel_mode_ = mode;} - void selectObject(ObjectBase * o, bool add_to_selection = false); - void selectObjects(ObjectBaseList ol, bool add_to_selection = false); - void selectObjectsByMesh(); - void selectObjectsByMaterial(); - void clearSelection(); - ObjectBaseList selectedObjects(bool top_only = false) const; - ObjectBase * selectedObject() const; - void cleanUnused(); - - const Box3D & boundingBox() const; - - QVector getMaterials() const {return materials;} - Material * newMaterial(const QString & name = QString()); - void removeMaterial(Material * m); - void makeMaterialsUniqueNames(); - - void removeLight(Light * l); - - void dump(); - void destroy(QOpenGLExtraFunctions * f); - void destroyUnused(QOpenGLExtraFunctions * f); - -protected: - void prepareTree(ObjectBase * o); - void gatherSelection(); - void objectsCountInternal(int * cnt, ObjectBase * where); - void removeObjectInternal(ObjectBase * o, ObjectBase * where); - void emitSelectionChanged(); - QString uniqueName(QString n, const QSet & names); - - void attachObject(ObjectBase * o); - Mesh * attachMesh(Mesh * mesh); - void setTreeChanged(); - void setTreeStructChanged(); - void setMaterialsChanged() {mat_changed = true;} - void setLightsChanged() {lights_changed = tree_changed = true;} - void setObjectMeshChanged(ObjectBase * o); - - - QString name_; - ObjectBase * root_; - bool tree_changed, mat_changed, lights_changed, destroying; - bool need_reload_materials, tree_struct_changed; - QVector mat_map_changed; - - QVector geometries, td_geometries; - QVector materials; - - QMap> geometries_used; // [pass][mesh] = ObjectBaseList - QMap> lights_used; // by Light::Type - QList cameras_used; - QVector changed_materials; - - SelectionMode sel_mode_; - ObjectBaseList selected_, selected_top; - -protected slots: - - -signals: - void __objectDeleted(ObjectBase * o); - void __destroyed(); - void treeChanged(); - //void treeStructChanged(); - void selectionChanged(); - -}; - - -QDataStream & operator <<(QDataStream & s, const Scene * p); -QDataStream & operator >>(QDataStream & s, Scene *& p); - -#endif // GLSCENE_H diff --git a/qglengine/gltexture_manager.cpp b/qglengine/gltexture_manager.cpp deleted file mode 100644 index fb226b1..0000000 --- a/qglengine/gltexture_manager.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* - QGL TextureManager - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "gltexture_manager.h" -#include "gltypes.h" - -QStringList TextureManager::search_pathes("."); - - -QVector3D colorVector(QRgb c) { - return QVector3D(((uchar*)(&c))[0] / 255.f, ((uchar*)(&c))[1] / 255.f, ((uchar*)(&c))[2] / 255.f); -} - - -QString TextureManager::findFile(const QString & path) { - return ::findFile(path, search_pathes); -} - - -GLuint TextureManager::loadTexture(const QString & path, bool ownership, bool bump) { - QString p = findFile(path); - if (p.isEmpty()) return 0; - int tid = textureID(p, bump); - if (tid > 0) { - //qDebug() << "[TextureManager] Found" << path << "as" << tid; - return tid; - } - QImage image(p); - if (bump) convertToNormal(image); - //qDebug() << p << image.width() << image.height() << image.format() << bump; - GLuint tid_ = tid; - createGLTexture(f, tid_, image);///currentQGLView->bindTexture(image, GL_TEXTURE_2D); - tid = tid_; - if (tid == 0) { - qDebug() << "[TextureManager] Can`t load" << p; - return tid; - } - qDebug() << "[TextureManager] Loaded" << p << "as" << tid; - if (ownership) { - tex_ids[bump ? 1 : 0].insert(p, tid); - tex_im [bump ? 1 : 0].insert(p, image); - } - return tid; -} - - -GLuint TextureManager::loadTexture(const QImage & im, bool ownership, bool bump) { - if (im.isNull()) return 0; - QImage image(im); - if (bump) convertToNormal(image); - GLuint tid = 0; - createGLTexture(f, tid, im);///currentQGLView->bindTexture(image, GL_TEXTURE_2D); - if (tid == 0) { - qDebug() << "[TextureManager] Can`t load image"; - return tid; - } - //qDebug() << "[TextureManager] Loaded image as" << tid; - return tid; -} - - -QImage TextureManager::loadTextureImage(const QString & path, bool bump) { - QString p = findFile(path); - if (p.isEmpty()) return QImage(); - QImage ret = tex_im[bump ? 1 : 0].value(p); - if (!ret.isNull()) return ret; - ret = QImage(p); - if (bump) convertToNormal(ret); - tex_im[bump ? 1 : 0].insert(p, ret); - return ret; -} - - -void TextureManager::reloadTexture(GLuint tid, const QString & path) { - QString p = findFile(path); - if (p.isEmpty() || (tid == 0)) return; - QImage image(p); - createGLTexture(f, tid, image); - if (tid == 0) { - qDebug() << "[TextureManager] Can`t load" << p; - return; - } - qDebug() << "[TextureManager] Reloaded" << p << "as" << tid; -} - - -void TextureManager::reloadTexture(GLuint tid, const QImage & im) { - if (im.isNull() || (tid == 0)) return; - QImage image(im); - createGLTexture(f, tid, image); - qDebug() << "[TextureManager] Reloaded" << tid; -} - - -void TextureManager::convertToNormal(QImage & im) { - if (im.isNull()) return; - QImage sim = im.convertToFormat(QImage::Format_ARGB32); - float sum[3] = {0., 0., 0.}; - llong a = 0; - const uchar * sd = sim.constBits(); - for (int i = 0; i < sim.height(); i++) { - for (int j = 0; j < sim.width(); j++) { - sum[2] += sd[a] / 255.f - 0.5f; ++a; - sum[1] += sd[a] / 255.f - 0.5f; ++a; - sum[0] += sd[a] / 255.f - 0.5f; ++a; - ++a; - } - } - float wh = sim.width() * sim.height(); - sum[0] /= wh; - sum[1] /= wh; - sum[2] /= wh; - //qDebug() << sum[0] << sum[1] << sum[2]; - if ((qAbs(sum[0]) <= 0.05f) && (qAbs(sum[1]) <= 0.05f) && (sum[2] >= 0.25f)) /// already normal - return; - //qDebug() << "convert to normal"; - QImage dim = QImage(sim.width(), sim.height(), QImage::Format_ARGB32); - int tx, ty, w = sim.width(), h = sim.height(); - a = 0; - uchar * dd = dim.bits(); - for (int i = 0; i < sim.height(); i++) { - for (int j = 0; j < sim.width(); j++) { - tx = j - 1; - tx = tx < 0 ? w + tx : tx % w; - ty = i - 1; - ty = ty < 0 ? h + ty : ty % h; - QVector3D p[3], res; - p[0] = colorVector(sim.pixel(j, i)); - p[1] = colorVector(sim.pixel(j, ty)); - p[2] = colorVector(sim.pixel(tx, i)); - res.setY(piClamp(0.5f + (p[0].length() - p[1].length()) / 2.f, 0.f, 1.f)); - res.setX(piClamp(0.5f - (p[0].length() - p[2].length()) / 2.f, 0.f, 1.f)); - tx = (j + 1) % w; - ty = (i + 1) % h; - p[1] = colorVector(sim.pixel(j, ty)); - p[2] = colorVector(sim.pixel(tx, i)); - res.setY(piClamp(0.5f + (p[0].length() - p[1].length()) / 2.f, 0.f, 1.f)); - res.setX(piClamp(0.5f - (p[0].length() - p[2].length()) / 2.f, 0.f, 1.f)); - res.setZ(1.f); - dd[a] = res.z() * 255; ++a; - dd[a] = res.y() * 255; ++a; - dd[a] = res.x() * 255; ++a; - dd[a] = 255; ++a; - } - } - im = dim; - //im.save("_normal.png"); -} - - -bool TextureManager::loadTextures() { - QFileInfoList fil; - foreach (const QString & i, tex_pathes) - loadTexture(i, true); - tex_pathes.clear(); - return true; -} - - -void TextureManager::deleteTextures() { - for (int i = 0; i < 2; ++i) { - QList texs = tex_ids[i].values(); - qDebug() << "[TextureManager] Delete" << texs.size() << "textures"; - if (!texs.isEmpty()) f->glDeleteTextures(texs.size(), &texs[0]); - tex_ids[i].clear(); - tex_im [i].clear(); - } -} - - -void TextureManager::deleteTexture(const QString & name) { - for (int i = 0; i < 2; ++i) { - if (tex_ids[i].contains(name)) { - GLuint id = tex_ids[i][name]; - f->glDeleteTextures(1, &id); - tex_ids[i].remove(name); - tex_im [i].remove(name); - } - } -} - - -void TextureManager::clearImageCache() { - tex_im[0].clear(); - tex_im[1].clear(); -} diff --git a/qglengine/gltexture_manager.h b/qglengine/gltexture_manager.h deleted file mode 100644 index 95af8b9..0000000 --- a/qglengine/gltexture_manager.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - QGL TextureManager - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLTEXTUREMANAGER_H -#define GLTEXTUREMANAGER_H - -#include -#include -#include -#include -#include - - -class TextureManager { -public: - TextureManager(QOpenGLExtraFunctions * f_): f(f_) {} - virtual ~TextureManager() {} - - static void addSearchPath(const QString & path) {if (!search_pathes.contains(path)) search_pathes << path;} - static void clearSearchPathes() {search_pathes.clear();} - static QStringList searchPathes() {return search_pathes;} - static QString findFile(const QString & path); - GLuint loadTexture(const QString & path, bool ownership = true, bool bump = false); - GLuint loadTexture(const QImage & image, bool ownership = true, bool bump = false); - QImage loadTextureImage(const QString & path, bool bump = false); - void reloadTexture(GLuint tid, const QString & path); - void reloadTexture(GLuint tid, const QImage & image); - int textureID (const QString & path, bool bump = false) {return tex_ids[bump ? 1 : 0][path];} - QImage textureImage(const QString & path, bool bump = false) {return tex_im [bump ? 1 : 0][path];} - void addTexture(const QString & path) {tex_pathes << path;} - bool loadTextures(); - void deleteTextures(); - void deleteTexture(const QString & name); - void clearImageCache(); - -protected: - static void convertToNormal(QImage & im); - - static QStringList search_pathes; - - QMap tex_ids[2]; - QMap tex_im [2]; - QStringList tex_pathes; - - QOpenGLExtraFunctions * f; - -}; - - -#endif // GLTEXTUREMANAGER_H diff --git a/qglengine/glwidget.cpp b/qglengine/glwidget.cpp deleted file mode 100644 index 921652b..0000000 --- a/qglengine/glwidget.cpp +++ /dev/null @@ -1,240 +0,0 @@ -/* - QGL GLWidget - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "glwidget.h" -#include "qglview.h" -#include - - -GLWidget::GLWidget(QWidget *parent) : QWidget(parent) { - view_ = new QGLView(); - view_->setFlags(windowFlags() | Qt::FramelessWindowHint); - container = QWidget::createWindowContainer(view_, this); - lay = new QVBoxLayout(this); - lay->addWidget(container); - lay->setContentsMargins(0, 0, 0, 0); - lay->setSpacing(0); - setMouseTracking(true); - setWindowIcon(QIcon("://icons/qglview.png")); - connect(view_, &QGLView::doubleClick, this, &GLWidget::viewDoubleClicked); -} - - -QColor GLWidget::backColor() const { - return view_->backColor(); -} - - -qreal GLWidget::lineWidth() const { - return view_->lineWidth(); -} - - -qreal GLWidget::FOV() const { - return view_->FOV(); -} - - -qreal GLWidget::depthStart() const { - return view_->depthStart(); -} - - -QColor GLWidget::ambientColor() const { - return view_->ambientColor(); -} - - -bool GLWidget::isLightEnabled() const { - return view_->isLightEnabled(); -} - - -bool GLWidget::isGrabMouseEnabled() const { - return view_->isGrabMouseEnabled(); -} - - -bool GLWidget::isMouseRotateEnabled() const { - return view_->isMouseRotateEnabled(); -} - - -bool GLWidget::isMouseSelectionEnabled() const { - return view_->isMouseSelectionEnabled(); -} - - -bool GLWidget::isCameraOrbit() const -{ - return view_->isCameraOrbit(); -} - - -bool GLWidget::isHoverHaloEnabled() const { - return view_->isHoverHaloEnabled(); -} - - -QColor GLWidget::hoverHaloColor() const { - return view_->hoverHaloColor(); -} - - -qreal GLWidget::hoverHaloFillAlpha() const { - return view_->hoverHaloFillAlpha(); -} - - -bool GLWidget::isSelectionHaloEnabled() const { - return view_->isSelectionHaloEnabled(); -} - - -QColor GLWidget::selectionHaloColor() const { - return view_->selectionHaloColor(); -} - - -qreal GLWidget::selectionHaloFillAlpha() const { - return view_->selectionHaloFillAlpha(); -} - - -Scene * GLWidget::scene() { - return view_->scene(); -} - - -void GLWidget::addObject(ObjectBase * o) { - view_->scene()->addObject(o); -} - - -QByteArray GLWidget::saveCamera() { - return view_->saveCamera(); -} - - -void GLWidget::restoreCamera(const QByteArray &ba) { - view_->restoreCamera(ba); -} - - -void GLWidget::stop() { - view_->stop(); -} - - -void GLWidget::start(float freq) { - view_->start(freq); -} - - -void GLWidget::setBackColor(const QColor & c) { - view_->setBackColor(c); -} - - -void GLWidget::setLineWidth(const qreal & arg) { - view_->setLineWidth(arg); -} - - -void GLWidget::setFOV(const qreal & arg) { - view_->setFOV(arg); -} - - -void GLWidget::setDepthStart(const qreal & arg) { - view_->setDepthStart(arg); -} - - -void GLWidget::setAmbientColor(const QColor & arg) { - view_->setAmbientColor(arg); -} - - -void GLWidget::setLightEnabled(const bool & arg) { - view_->setLightEnabled(arg); -} - - -void GLWidget::setGrabMouseEnabled(const bool & arg) { - view_->setGrabMouseEnabled(arg); -} - - -void GLWidget::setMouseRotateEnabled(const bool & arg) { - view_->setMouseRotateEnabled(arg); -} - - -void GLWidget::setMouseSelectionEnabled(const bool & arg) { - view_->setMouseSelectionEnabled(arg); -} - - -void GLWidget::setCameraOrbit(const bool & arg) { - view_->setCameraOrbit(arg); -} - - -void GLWidget::setHoverHaloEnabled(const bool & arg) { - view_->setHoverHaloEnabled(arg); -} - - -void GLWidget::setHoverHaloColor(const QColor & arg) { - view_->setHoverHaloColor(arg); -} - - -void GLWidget::setHoverHaloFillAlpha(const qreal & arg) { - view_->setHoverHaloFillAlpha(arg); -} - - -void GLWidget::setSelectionHaloEnabled(const bool & arg) { - view_->setSelectionHaloEnabled(arg); -} - - -void GLWidget::setSelectionHaloColor(const QColor & arg) { - view_->setSelectionHaloColor(arg); -} - - -void GLWidget::setSelectionHaloFillAlpha(const qreal & arg) { - view_->setSelectionHaloFillAlpha(arg); -} - - -void GLWidget::viewDoubleClicked() { - if (view_->windowState() == Qt::WindowFullScreen) { - view_->showNormal(); - container = QWidget::createWindowContainer(view_, this); - lay->addWidget(container); - container->show(); - } else { - view_->setParent(nullptr); - view_->showFullScreen(); - lay->removeWidget(container); - } -} diff --git a/qglengine/glwidget.h b/qglengine/glwidget.h deleted file mode 100644 index b72265d..0000000 --- a/qglengine/glwidget.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - QGL GLWidget - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef GLWIDGET_H -#define GLWIDGET_H - -#include - - -class QGLView; -class ObjectBase; -class Scene; - -class GLWidget : public QWidget -{ - Q_OBJECT - Q_PROPERTY (QColor backColor READ backColor WRITE setBackColor) - Q_PROPERTY (qreal lineWidth READ lineWidth WRITE setLineWidth) - Q_PROPERTY (qreal FOV READ FOV WRITE setFOV) - Q_PROPERTY (qreal depthStart READ depthStart WRITE setDepthStart) - Q_PROPERTY (QColor ambientColor READ ambientColor WRITE setAmbientColor) - Q_PROPERTY (bool grabMouse READ isGrabMouseEnabled WRITE setGrabMouseEnabled) - Q_PROPERTY (bool mouseRotate READ isMouseRotateEnabled WRITE setMouseRotateEnabled) - Q_PROPERTY (bool mouseSelection READ isMouseSelectionEnabled WRITE setMouseSelectionEnabled) - Q_PROPERTY (bool cameraOrbit READ isCameraOrbit WRITE setCameraOrbit) - Q_PROPERTY (bool hoverHalo READ isHoverHaloEnabled WRITE setHoverHaloEnabled) - Q_PROPERTY (QColor hoverHaloColor READ hoverHaloColor WRITE setHoverHaloColor) - Q_PROPERTY (qreal hoverHaloFillAlpha READ hoverHaloFillAlpha WRITE setHoverHaloFillAlpha) - Q_PROPERTY (bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled) - Q_PROPERTY (QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor) - Q_PROPERTY (qreal selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha) -public: - explicit GLWidget(QWidget *parent = nullptr); - QGLView * view() {return view_;} - - QColor backColor() const; - qreal lineWidth() const; - qreal FOV() const; - qreal depthStart() const; - QColor ambientColor() const; - bool isLightEnabled() const; - bool isGrabMouseEnabled() const; - bool isMouseRotateEnabled() const; - bool isMouseSelectionEnabled() const; - bool isCameraOrbit() const; - bool isHoverHaloEnabled() const; - QColor hoverHaloColor() const; - qreal hoverHaloFillAlpha() const; - bool isSelectionHaloEnabled() const; - QColor selectionHaloColor() const; - qreal selectionHaloFillAlpha() const; - Scene * scene(); - - void addObject(ObjectBase * o); - QByteArray saveCamera(); - void restoreCamera(const QByteArray & ba); - -public slots: - void stop(); - void start(float freq = 60.0); - void setBackColor(const QColor & c); - void setLineWidth(const qreal & arg); - void setFOV(const qreal & arg); - void setDepthStart(const qreal & arg); - void setAmbientColor(const QColor & arg); - void setLightEnabled(const bool & arg); - void setGrabMouseEnabled(const bool & arg); - void setMouseRotateEnabled(const bool & arg); - void setMouseSelectionEnabled(const bool & arg); - void setCameraOrbit(const bool & arg); - void setHoverHaloEnabled(const bool & arg); - void setHoverHaloColor(const QColor & arg); - void setHoverHaloFillAlpha(const qreal & arg); - void setSelectionHaloEnabled(const bool & arg); - void setSelectionHaloColor(const QColor & arg); - void setSelectionHaloFillAlpha(const qreal & arg); - -private slots: - void viewDoubleClicked(); - -private: - QWidget * container; - QGLView * view_; - QLayout * lay; - -signals: -}; - -#endif // GLWIDGET_H diff --git a/qglengine/icons/add-type-camera.png b/qglengine/icons/add-type-camera.png deleted file mode 100644 index 13b5588..0000000 Binary files a/qglengine/icons/add-type-camera.png and /dev/null differ diff --git a/qglengine/icons/add-type-empty.png b/qglengine/icons/add-type-empty.png deleted file mode 100644 index df5f5b3..0000000 Binary files a/qglengine/icons/add-type-empty.png and /dev/null differ diff --git a/qglengine/icons/add-type-geo.png b/qglengine/icons/add-type-geo.png deleted file mode 100644 index b983991..0000000 Binary files a/qglengine/icons/add-type-geo.png and /dev/null differ diff --git a/qglengine/icons/add-type-light.png b/qglengine/icons/add-type-light.png deleted file mode 100644 index a896c1a..0000000 Binary files a/qglengine/icons/add-type-light.png and /dev/null differ diff --git a/qglengine/icons/alpha.png b/qglengine/icons/alpha.png deleted file mode 100644 index 5435669..0000000 Binary files a/qglengine/icons/alpha.png and /dev/null differ diff --git a/qglengine/icons/application-exit.png b/qglengine/icons/application-exit.png deleted file mode 100644 index 8adbcba..0000000 Binary files a/qglengine/icons/application-exit.png and /dev/null differ diff --git a/qglengine/icons/collapse.png b/qglengine/icons/collapse.png deleted file mode 100644 index ec329aa..0000000 Binary files a/qglengine/icons/collapse.png and /dev/null differ diff --git a/qglengine/icons/configure.png b/qglengine/icons/configure.png deleted file mode 100644 index 2a81957..0000000 Binary files a/qglengine/icons/configure.png and /dev/null differ diff --git a/qglengine/icons/dialog-cancel.png b/qglengine/icons/dialog-cancel.png deleted file mode 100644 index ace88ab..0000000 Binary files a/qglengine/icons/dialog-cancel.png and /dev/null differ diff --git a/qglengine/icons/dialog-close.png b/qglengine/icons/dialog-close.png deleted file mode 100644 index 6072634..0000000 Binary files a/qglengine/icons/dialog-close.png and /dev/null differ diff --git a/qglengine/icons/document-edit.png b/qglengine/icons/document-edit.png deleted file mode 100644 index 1ecb10c..0000000 Binary files a/qglengine/icons/document-edit.png and /dev/null differ diff --git a/qglengine/icons/document-import.png b/qglengine/icons/document-import.png deleted file mode 100644 index 8cc3eb0..0000000 Binary files a/qglengine/icons/document-import.png and /dev/null differ diff --git a/qglengine/icons/document-new.png b/qglengine/icons/document-new.png deleted file mode 100644 index e4d8b47..0000000 Binary files a/qglengine/icons/document-new.png and /dev/null differ diff --git a/qglengine/icons/document-open.png b/qglengine/icons/document-open.png deleted file mode 100644 index 63380e4..0000000 Binary files a/qglengine/icons/document-open.png and /dev/null differ diff --git a/qglengine/icons/document-save-all.png b/qglengine/icons/document-save-all.png deleted file mode 100644 index 73405f7..0000000 Binary files a/qglengine/icons/document-save-all.png and /dev/null differ diff --git a/qglengine/icons/document-save.png b/qglengine/icons/document-save.png deleted file mode 100644 index aee3e22..0000000 Binary files a/qglengine/icons/document-save.png and /dev/null differ diff --git a/qglengine/icons/edit-clear-locationbar-rtl.png b/qglengine/icons/edit-clear-locationbar-rtl.png deleted file mode 100644 index 0e6d645..0000000 Binary files a/qglengine/icons/edit-clear-locationbar-rtl.png and /dev/null differ diff --git a/qglengine/icons/edit-clear.png b/qglengine/icons/edit-clear.png deleted file mode 100644 index cae930b..0000000 Binary files a/qglengine/icons/edit-clear.png and /dev/null differ diff --git a/qglengine/icons/edit-copy.png b/qglengine/icons/edit-copy.png deleted file mode 100644 index a8178ca..0000000 Binary files a/qglengine/icons/edit-copy.png and /dev/null differ diff --git a/qglengine/icons/edit-delete.png b/qglengine/icons/edit-delete.png deleted file mode 100644 index 38f11cd..0000000 Binary files a/qglengine/icons/edit-delete.png and /dev/null differ diff --git a/qglengine/icons/edit-find.png b/qglengine/icons/edit-find.png deleted file mode 100644 index 140e581..0000000 Binary files a/qglengine/icons/edit-find.png and /dev/null differ diff --git a/qglengine/icons/edit-paste.png b/qglengine/icons/edit-paste.png deleted file mode 100644 index a9aac10..0000000 Binary files a/qglengine/icons/edit-paste.png and /dev/null differ diff --git a/qglengine/icons/edit-rename.png b/qglengine/icons/edit-rename.png deleted file mode 100644 index 4b47837..0000000 Binary files a/qglengine/icons/edit-rename.png and /dev/null differ diff --git a/qglengine/icons/expand.png b/qglengine/icons/expand.png deleted file mode 100644 index 6a963b6..0000000 Binary files a/qglengine/icons/expand.png and /dev/null differ diff --git a/qglengine/icons/format-fill-color.png b/qglengine/icons/format-fill-color.png deleted file mode 100644 index 99412e9..0000000 Binary files a/qglengine/icons/format-fill-color.png and /dev/null differ diff --git a/qglengine/icons/go-jump.png b/qglengine/icons/go-jump.png deleted file mode 100644 index 7437eff..0000000 Binary files a/qglengine/icons/go-jump.png and /dev/null differ diff --git a/qglengine/icons/go-top.png b/qglengine/icons/go-top.png deleted file mode 100644 index 489674e..0000000 Binary files a/qglengine/icons/go-top.png and /dev/null differ diff --git a/qglengine/icons/group.png b/qglengine/icons/group.png deleted file mode 100644 index 5108637..0000000 Binary files a/qglengine/icons/group.png and /dev/null differ diff --git a/qglengine/icons/layer-visible-off.png b/qglengine/icons/layer-visible-off.png deleted file mode 100644 index b1f04a9..0000000 Binary files a/qglengine/icons/layer-visible-off.png and /dev/null differ diff --git a/qglengine/icons/layer-visible-on.png b/qglengine/icons/layer-visible-on.png deleted file mode 100644 index 9117bea..0000000 Binary files a/qglengine/icons/layer-visible-on.png and /dev/null differ diff --git a/qglengine/icons/light-+.png b/qglengine/icons/light-+.png deleted file mode 100644 index e7d8d80..0000000 Binary files a/qglengine/icons/light-+.png and /dev/null differ diff --git a/qglengine/icons/list-add.png b/qglengine/icons/list-add.png deleted file mode 100644 index a15dd10..0000000 Binary files a/qglengine/icons/list-add.png and /dev/null differ diff --git a/qglengine/icons/object-flip-horizontal.png b/qglengine/icons/object-flip-horizontal.png deleted file mode 100644 index 2c0579e..0000000 Binary files a/qglengine/icons/object-flip-horizontal.png and /dev/null differ diff --git a/qglengine/icons/object-flip-vertical.png b/qglengine/icons/object-flip-vertical.png deleted file mode 100644 index 7a9ee82..0000000 Binary files a/qglengine/icons/object-flip-vertical.png and /dev/null differ diff --git a/qglengine/icons/picker.png b/qglengine/icons/picker.png deleted file mode 100644 index da411da..0000000 Binary files a/qglengine/icons/picker.png and /dev/null differ diff --git a/qglengine/icons/transform-move.png b/qglengine/icons/transform-move.png deleted file mode 100644 index b20fc44..0000000 Binary files a/qglengine/icons/transform-move.png and /dev/null differ diff --git a/qglengine/icons/transform-rotate.png b/qglengine/icons/transform-rotate.png deleted file mode 100644 index 5063158..0000000 Binary files a/qglengine/icons/transform-rotate.png and /dev/null differ diff --git a/qglengine/icons/transform-scale.png b/qglengine/icons/transform-scale.png deleted file mode 100644 index 9ff1d44..0000000 Binary files a/qglengine/icons/transform-scale.png and /dev/null differ diff --git a/qglengine/icons/type-camera.png b/qglengine/icons/type-camera.png deleted file mode 100644 index e7fcde0..0000000 Binary files a/qglengine/icons/type-camera.png and /dev/null differ diff --git a/qglengine/icons/type-empty.png b/qglengine/icons/type-empty.png deleted file mode 100644 index 337f0de..0000000 Binary files a/qglengine/icons/type-empty.png and /dev/null differ diff --git a/qglengine/icons/type-geo.png b/qglengine/icons/type-geo.png deleted file mode 100644 index d6b825c..0000000 Binary files a/qglengine/icons/type-geo.png and /dev/null differ diff --git a/qglengine/icons/type-light.png b/qglengine/icons/type-light.png deleted file mode 100644 index 5301173..0000000 Binary files a/qglengine/icons/type-light.png and /dev/null differ diff --git a/qglengine/icons/view-refresh.png b/qglengine/icons/view-refresh.png deleted file mode 100644 index 66f0ceb..0000000 Binary files a/qglengine/icons/view-refresh.png and /dev/null differ diff --git a/qglengine/mouse_controller.cpp b/qglengine/mouse_controller.cpp deleted file mode 100644 index ddecef9..0000000 --- a/qglengine/mouse_controller.cpp +++ /dev/null @@ -1,289 +0,0 @@ -/* - QGL MouseController - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "mouse_controller.h" -#include "glmesh.h" -#include "qglview.h" -#include -#include -#include - -using namespace QGLEngineShaders; - - -MouseController::MouseController(QGLView * view_): view(view_) { - app_scale = 1; - lastPos = QPoint(-1, -1); - cur_action = RendererService::haNoAction; - sel_button = Qt::LeftButton; - sel_mod = Qt::ControlModifier; - mouse_first = mouseSelect_ = mouseRotate_ = cameraOrbit_ = canSelect_ = true; - grabMouse_ = mouse_sec = selecting_ = customMouseMove_ = false; -} - - -MouseController::~MouseController() { -} - - -void MouseController::resize() { - mouse_first = true; - app_scale = appScale(); -} - - -void MouseController::mouseReleaseEvent(QMouseEvent * e) { - if (cur_action != RendererService::haNoAction) { - mouseMoveEvent(e); - return; - } - bool add_ts = e->modifiers().testFlag(sel_mod); - if (selecting_) { - selecting_ = false; - canSelect_ = true; - view->renderer_.mouse_rect = QRect(); - view->scene_->selectObjects(hov_objects.toList(), add_ts); - return; - } - if (canSelect_ && mouseSelect_) { - if ((lastPos - downPos).manhattanLength() < QApplication::startDragDistance()) { - if (e->button() == Qt::LeftButton) { - //qDebug() << hov_objects << hov_aims; - if (hov_objects.isEmpty() && hov_aims.isEmpty()) { - view->scene()->clearSelection(); - } else { - if (!hov_objects.isEmpty()) - view->scene_->selectObject(hov_objects[0], add_ts); - if (!hov_aims.isEmpty()) { - view->scene_->selectObject(hov_aims[0], add_ts); - hov_aims[0]->selected_aim = true; - } - } - } - if (e->button() == Qt::RightButton) { - if (view->renderer_.edit_mode && !view->scene()->selectedObjects().isEmpty()) - view->context_menu.popup(e->globalPos()); - } - } - } - canSelect_ = e->buttons() == 0; - emit view->glMouseReleaseEvent(e); -} - - -void MouseController::mousePressEvent(QMouseEvent * e) { - downPos = e->pos(); - if (cur_action != RendererService::haNoAction && e->buttons() == Qt::LeftButton) { - return; - } - if (selecting_) { - selecting_ = false; - view->renderer_.mouse_rect = QRect(); - return; - } - if (!QRect(QPoint(), view->size()).contains(e->pos())) return; - lastPos = e->pos(); - downPos = e->pos(); - emit view->glMousePressEvent(e); -} - - -void MouseController::mouseMoveEvent(QMouseEvent * e) { - QPoint cpos = e->pos(); - if (cur_action != RendererService::haNoAction && (e->buttons() == Qt::LeftButton)) { - RendererService & rs(view->renderer_.rend_service); - ObjectBaseList objects = view->scene_->selectedObjects(true); - QVector axis; - switch (cur_action) { - case RendererService::haMove: - if (cur_handle.testFlag(RendererService::hmMoveX)) axis << 0; - if (cur_handle.testFlag(RendererService::hmMoveY)) axis << 1; - if (cur_handle.testFlag(RendererService::hmMoveZ)) axis << 2; - break; - case RendererService::haRotate: - if (cur_handle.testFlag(RendererService::hmRotateX)) axis << 0; - if (cur_handle.testFlag(RendererService::hmRotateY)) axis << 1; - if (cur_handle.testFlag(RendererService::hmRotateZ)) axis << 2; - break; - case RendererService::haScale: - if (cur_handle.testFlag(RendererService::hmScaleX)) axis << 0; - if (cur_handle.testFlag(RendererService::hmScaleY)) axis << 1; - if (cur_handle.testFlag(RendererService::hmScaleZ)) axis << 2; - break; - default: break; - } - QVector scales; - foreach (int a, axis) { - QVector3D axe_vector; axe_vector[a] = 1.; - QMatrix4x4 axis_mat = view->camera()->fullViewMatrix() * rs.axis_mat; - QVector3D center_screen = axis_mat * rs.selection_center; - QVector3D axe_screen = ((axis_mat * (rs.selection_center + axe_vector)) - center_screen).normalized(); - QVector3D mouse_vector(cpos - lastPos); - mouse_vector[1] *= -1.; - if (cur_action == RendererService::haMove) { - double len_scl = 1. / QVector3D(axe_screen.x(), axe_screen.y(), 1.E-6).length(); - mouse_vector /= QVector3D(view->width(), view->height(), 1); - mouse_vector *= -center_screen.z() * len_scl; - axe_vector *= QVector3D::dotProduct(axe_screen, mouse_vector); - QMatrix4x4 pmat; - foreach (ObjectBase * o, objects) { - pmat.setToIdentity(); - if (o->parent()) - pmat = o->parent()->worldTransform().inverted(); - QVector3D dv = pmat.mapVector(axe_vector); - if (o->selected_aim) { - AimedObject * ao = (AimedObject*)o; - ao->setAim(ao->aim() + dv); - } else - o->move(dv); - } - } - if (cur_action == RendererService::haRotate) { - axe_screen.setZ(0.); - axe_screen.normalize(); - QVector3D norm = QVector3D(axe_screen.y(), -axe_screen.x(), 0.); - axe_vector *= QVector3D::dotProduct(mouse_vector, norm) / 2. / app_scale; - foreach (ObjectBase * o, objects) - o->setRotation(o->rotation() + axe_vector); - } - if (cur_action == RendererService::haScale) { - mouse_vector /= QVector3D(view->width(), view->height(), 1); - mouse_vector *= 3. / app_scale; - axe_vector *= QVector3D::dotProduct(axe_screen, mouse_vector); - scales << axe_vector; - } - } - //if (cur_handle >= RendererService::htScaleX && cur_handle <= RendererService::htScaleZ ) cs = Qt::SplitHCursor; - if (cur_action == RendererService::haScale) { - double sc = 0., max = 0.; - foreach (const QVector3D & s, scales) { - double v = QVector3D::dotProduct(s, QVector3D(1,1,1)); - sc += v; - max = qMax(max, qAbs(v)); - } - sc = max * (sc > 0. ? 1. : -1); - QVector3D axe_vector; - foreach (int a, axis) - axe_vector[a] = 1.; - foreach (ObjectBase * o, objects) - o->scale(QVector3D(1,1,1) + (axe_vector * sc)); - QCursor::setPos(view->mapToGlobal(downPos)); - } else - lastPos = e->pos(); - emit view->objectsPositionChanged(); - return; - } - if (selecting_) { - view->renderer_.mouse_rect = QRect(downPos, cpos).normalized(); - return; - } - if (e->buttons().testFlag(Qt::LeftButton)) { - if ((cpos - downPos).manhattanLength() >= QApplication::startDragDistance()) { - selecting_ = true; - canSelect_ = false; - } - return; - } - QRect g_rect(QPoint(), view->size()); - if (mouseRotate_) { - float dx = e->x() - lastPos.x(); - float dy = e->y() - lastPos.y(); - if (e->buttons().testFlag(Qt::MidButton)) { - if (cameraOrbit_) { - view->camera()->orbitZ (dx / 4.f); - view->camera()->orbitXY(dy / 4.f); - } else { - view->camera()->rotateZ(-dx / 4.f); - view->camera()->rotateX(-dy / 4.f); - } - emit view->cameraPosChanged(view->camera()->pos()); - } else if (e->buttons().testFlag(Qt::RightButton)) { - float ad = view->camera()->distance(); - view->camera()->moveLeft(dx / 1000.f * ad); - view->camera()->moveUp (dy / 1000.f * ad); - emit view->cameraPosChanged(view->camera()->pos()); - } - } - if (customMouseMove_) emit view->customMouseMoveEvent(e->pos(), lastPos, e->buttons()); - lastPos = e->pos(); - if (e->buttons() == 0) { - cur_handle = 0; - cur_action = RendererService::haNoAction; - Qt::CursorShape cs = Qt::CrossCursor; - if (view->renderer_.edit_mode) { - uint hid = view->renderer_.rend_selection.id_hover; - cur_handle = (RendererService::HandleMesh)hid; - if (hid >= RendererService::hmMoveX && hid <= RendererService::hmMaxMove ) { - cur_action = RendererService::haMove; - cs = Qt::SizeAllCursor; - } - if (hid >= RendererService::hmRotateX && hid <= RendererService::hmMaxRotate) { - cur_action = RendererService::haRotate; - cs = Qt::PointingHandCursor; - } - if (hid >= RendererService::hmScaleX && hid <= RendererService::hmMaxScale ) { - cur_action = RendererService::haScale; - cs = Qt::SplitHCursor; - } - } - if (cur_action == RendererService::haNoAction) - cur_handle = 0; - view->setCursor(cs); - view->renderer_.rend_service.current_handle = cur_handle; - } - if (grabMouse_) { - QCursor::setPos(view->mapToGlobal(QRect(QPoint(), view->size()).center())); - if (mouse_sec) { - mouse_sec = false; - return; - } - if (mouse_first) { - mouse_first = false; - mouse_sec = true; - return; - } - lastPos = g_rect.center(); - int dx = e->x() - lastPos.x(); - int dy = e->y() - lastPos.y(); - emit view->glMouseMoveEvent(new QMouseEvent(QEvent::MouseMove, QPoint(dx, dy), e->button(), e->buttons(), e->modifiers())); - return; - } - emit view->glMouseMoveEvent(e); -} - - -void MouseController::wheelEvent(QWheelEvent * e) { - if (mouseRotate_) { - if (e->delta() > 0) view->camera()->flyCloser(0.1f); - if (e->delta() < 0) view->camera()->flyFarer(0.1f); - emit view->cameraPosChanged(view->camera()->pos()); - } - emit view->glWheelEvent(e); -} - - -void MouseController::leaveEvent(QEvent * ) { - lastPos = QPoint(-1, -1); - //qDebug() << lastPos; -} - - -void MouseController::mouseDoubleClickEvent(QMouseEvent * e) { - if (e->buttons().testFlag(Qt::MidButton)) - emit view->doubleClick(); -} diff --git a/qglengine/mouse_controller.h b/qglengine/mouse_controller.h deleted file mode 100644 index 2c93986..0000000 --- a/qglengine/mouse_controller.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - QGL MouseController - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef MOUSE_CONTROLLER_H -#define MOUSE_CONTROLLER_H - -#include "glprimitives.h" -#include "glcamera.h" -#include "renderer_service.h" -#include -#include - - -class MouseController: public QObject -{ - friend class QGLView; - friend class RendererSelection; - Q_OBJECT -public: - MouseController(QGLView * view_); - virtual ~MouseController(); - - bool isGrabMouseEnabled() const {return grabMouse_;} - bool isMouseRotateEnabled() const {return mouseRotate_;} - bool isMouseSelectionEnabled() const {return mouseSelect_;} - bool isCameraOrbit() const {return cameraOrbit_;} - - Qt::MouseButton selectionButton() const {return sel_button;} - Qt::KeyboardModifier selectionModifier() const {return sel_mod;} - - void setSelectionButton(Qt::MouseButton v) {sel_button = v;} - void setSelectionModifier(Qt::KeyboardModifier v) {sel_mod = v;} - -protected: - void resize(); - void mousePressEvent(QMouseEvent * e); - void mouseMoveEvent(QMouseEvent * e); - void mouseReleaseEvent(QMouseEvent * e); - void wheelEvent(QWheelEvent * e); - void leaveEvent(QEvent * ); - void mouseDoubleClickEvent(QMouseEvent * e); - -private: - QGLView * view; - QPoint lastPos, downPos; - QSet keys_; - QVector hov_objects, hov_aims; - Qt::MouseButton sel_button; - Qt::KeyboardModifier sel_mod; - RendererService::HandleAction cur_action; - QFlags cur_handle; - float app_scale; - bool grabMouse_, mouse_first, mouseRotate_, mouseSelect_, customMouseMove_, canSelect_; - bool cameraOrbit_, selecting_, mouse_sec; - -private slots: - -public slots: - void setGrabMouseEnabled(const bool & arg) {grabMouse_ = arg; mouse_first = true;} - void setMouseRotateEnabled(const bool & arg) {mouseRotate_ = arg;} - void setMouseSelectionEnabled(const bool & arg) {mouseSelect_ = arg;} - void setCustomMouseMove(const bool & arg) {customMouseMove_ = arg;} - void setCameraOrbit(const bool & arg) {cameraOrbit_ = arg;} - -signals: - -}; - -#endif // QGLVIEW_H diff --git a/qglengine/openglwindow.cpp b/qglengine/openglwindow.cpp deleted file mode 100644 index 8b29356..0000000 --- a/qglengine/openglwindow.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - QGL OpenGLWindow - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "openglwindow.h" -#include -#include -#include -#include - - -OpenGLWindow::OpenGLWindow(QWindow *parent) - : QWindow(parent) - , m_context(nullptr) - , m_device(nullptr) -{ - setFlags(flags() | Qt::FramelessWindowHint); - setSurfaceType(QWindow::OpenGLSurface); - QSurfaceFormat format = QSurfaceFormat::defaultFormat(); -// qDebug() << format; -#ifdef QT_OPENGL_ES_2 - format.setRenderableType(QSurfaceFormat::OpenGLES); -#else - if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) { - format.setVersion(4, 0); - format.setProfile(QSurfaceFormat::CoreProfile); - } -#endif - format.setDepthBufferSize(24); - format.setSamples(8); -// format.setStencilBufferSize(8); - setFormat(format); - QSurfaceFormat::setDefaultFormat(format); -} - - -OpenGLWindow::~OpenGLWindow() { - delete m_device; -} - - -void OpenGLWindow::render(QPainter *painter) { -} - - -void OpenGLWindow::initialize() { -} - - -void OpenGLWindow::render() { -// if (!m_device) m_device = new QOpenGLPaintDevice; -// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); -// m_device->setSize(size() * devicePixelRatio()); -// m_device->setDevicePixelRatio(devicePixelRatio()); -// QPainter painter(m_device); -// render(&painter); -} - - -void OpenGLWindow::renderLater() { - requestUpdate(); -} - - -bool OpenGLWindow::event(QEvent *event) { - switch (event->type()) { - case QEvent::UpdateRequest: - renderNow(); - return true; - default: - return QWindow::event(event); - } -} - - -void OpenGLWindow::exposeEvent(QExposeEvent *event) { - if (isExposed()) renderNow(); -} - - -void OpenGLWindow::renderNow() { - if (!isExposed()) - return; - bool needsInitialize = false; - if (!m_context) { - m_context = new QOpenGLContext(this); - m_context->setFormat(requestedFormat()); - m_context->create(); - needsInitialize = true; - } - m_context->makeCurrent(this); - if (needsInitialize) { - initializeOpenGLFunctions(); - initialize(); - } - render(); - m_context->swapBuffers(this); -} - diff --git a/qglengine/openglwindow.h b/qglengine/openglwindow.h deleted file mode 100644 index 2110b7c..0000000 --- a/qglengine/openglwindow.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - QGL OpenGLWindow - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include -#include - -class QPainter; -class QOpenGLContext; -class QOpenGLPaintDevice; - - -class OpenGLWindow: public QWindow, protected QOpenGLExtraFunctions -{ - Q_OBJECT -public: - explicit OpenGLWindow(QWindow *parent = nullptr); - ~OpenGLWindow(); - - virtual void render(QPainter *painter); - virtual void render(); - - virtual void initialize(); - - QOpenGLContext * context() {return m_context;} - -public slots: - void renderLater(); - void renderNow(); - -protected: - bool event(QEvent *event) override; - - void exposeEvent(QExposeEvent *event) override; - -private: - QOpenGLContext *m_context; - QOpenGLPaintDevice *m_device; -}; - diff --git a/qglengine/plugin/CMakeLists.txt b/qglengine/plugin/CMakeLists.txt deleted file mode 100644 index 22bcdc5..0000000 --- a/qglengine/plugin/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -if (DESIGNER_PLUGINS) - if (NOT Qt5) - message(WARNING "Building ${PROJECT_NAME} available only on Qt5!") - else() - project(qglengine_plugin) - include_directories("..") - add_definitions(-DQT_PLUGIN) - add_definitions(-DQT_NO_DEBUG) - add_definitions(-DQT_SHARED) - add_definitions(-DQDESIGNER_EXPORT_WIDGETS) - find_qt(Qt5 Core Designer Gui Widgets OpenGL) - qt_sources(SRC) - qt_wrap(${SRC} CPPS out_CPP QMS out_QM) - qt_add_library(${PROJECT_NAME} SHARED out_CPP) - qt_target_link_libraries(${PROJECT_NAME} qglengine) - qt_install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION QtPlugins/designer) - endif() -endif() diff --git a/qglengine/plugin/qglviewplugin.cpp b/qglengine/plugin/qglviewplugin.cpp deleted file mode 100644 index 97db1e4..0000000 --- a/qglengine/plugin/qglviewplugin.cpp +++ /dev/null @@ -1,95 +0,0 @@ -#include "../glwidget.h" -#include "qglviewplugin.h" -#include -#include "glprimitives.h" -#include "qglview.h" - - -QGLViewPlugin::QGLViewPlugin(QObject * parent): QObject(parent) { - m_initialized = false; -} - - -void QGLViewPlugin::initialize(QDesignerFormEditorInterface * /* core */) { - if (m_initialized) - return; - - // Add extension registrations, etc. here - - m_initialized = true; -} - - -bool QGLViewPlugin::isInitialized() const { - return m_initialized; -} - - -QWidget * QGLViewPlugin::createWidget(QWidget * parent) { - GLWidget * w = new GLWidget(parent); - if (m_initialized) { - auto axis = new GLObjectBase(); - GLObjectBase * obj; - float al = 1.; - obj = new GLPrimitiveLine(QVector3D(0, 0, -al), QVector3D(0, 0, al)); - obj->material().color_diffuse = Qt::darkBlue; obj->setAcceptLight(false); - obj->setSelectable(false); - axis->addChild(obj); - obj = new GLPrimitiveLine(QVector3D(-al, 0, 0), QVector3D(al, 0, 0)); - obj->material().color_diffuse = Qt::darkRed; obj->setAcceptLight(false); - obj->setSelectable(false); - axis->addChild(obj); - obj = new GLPrimitiveLine(QVector3D(0, -al, 0), QVector3D(0, al, 0)); - obj->material().color_diffuse = Qt::darkGreen; obj->setAcceptLight(false); - obj->setSelectable(false); - axis->addChild(obj); - w->view()->addObject(axis); - auto cam_light = new Light(); - cam_light->intensity = 0.5; - cam_light->setName("Camera_Light"); - w->view()->camera()->addChild(cam_light); - w->start(); - } - return w; -} - - -QString QGLViewPlugin::name() const { - return QLatin1String("GLWidget"); -} - - -QString QGLViewPlugin::group() const { - return QLatin1String("Display Widgets"); -} - - -QIcon QGLViewPlugin::icon() const { - return QIcon("://icons/qglview.png"); -} - - -QString QGLViewPlugin::toolTip() const { - return QLatin1String(""); -} - - -QString QGLViewPlugin::whatsThis() const { - return QLatin1String(""); -} - - -bool QGLViewPlugin::isContainer() const { - return false; -} - - -QString QGLViewPlugin::domXml() const { - return QLatin1String("\n\n"); -} - - -QString QGLViewPlugin::includeFile() const { - return QLatin1String("glwidget.h"); -} - diff --git a/qglengine/qglview.cpp b/qglengine/qglview.cpp deleted file mode 100644 index cbff22e..0000000 --- a/qglengine/qglview.cpp +++ /dev/null @@ -1,299 +0,0 @@ -/* - QGLView - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "qglview.h" -#include "glmesh.h" -#include "gltexture_manager.h" -#include -#include -#include -#include -#include - -using namespace QGLEngineShaders; - - -QGLView::QGLView(): OpenGLWindow(), renderer_(this), mouse(this) { - setIcon(QIcon(":/icons/qglview.png")); - deleting_ = false; - timer = 0; - need_init_ = is_first_draw = true; - backColor_ = Qt::darkGray; - hoverHaloColor_ = QColor(195, 140, 255); - selectionHaloColor_ = QColor(175, 255, 140); - ambientColor_ = QColor(10, 10, 10); - lineWidth_ = 1.; - max_anisotropic = 1; - max_texture_chanels = 8; - lightEnabled_ = true; - shaders_supported = false; - fps_cnt = 0; - fps_tm = fps_ = 0.; - fogColor_ = Qt::darkGray; - fogDensity_ = 0.; - fogDecay_ = 10.; - hoverHaloFill_ = selectionHaloFill_ = 0.15f; - //lmode = Simple; - setFeature(qglFXAA, false); - setFeature(qglAnisotropicLevel, 8); - setFeature(qglEyeAccomodationEnabled, false); - setFeature(qglEyeAccomodationTime, 16.); - setFeature(qglEyeAccomodationMaxSpeed, 0.2); - setFeature(qglBloomEnabled, false); - setFeature(qglBloomThreshold, 0.9); - setFeature(qglBloomFactor, 1.); - setFeature(qglBloomRadius, 8); - setFeature(qglMotionBlurEnabled, false); - setFeature(qglMotionBlurFactor, 1.); - setFeature(qglMotionBlurSteps, 8); - setFeature(qglShadowsEnabled, false); - setFeature(qglShadowsMapSize, 512); - setFeature(qglShadowsSoftEnabled, true); - setFeature(qglReflectionsEnabled, false); - setFeature(qglReflectionsBlur, true); - setFeature(qglSSAOEnabled, false); - setFeature(qglSSAORadius, 5); - setFeature(qglDepthOfFieldEnabled, false); - setFeature(qglDepthOfFieldAutoFocusEnabled, true); - setFeature(qglDepthOfFieldAutoFocusSpeed, 0.1); - setFeature(qglDepthOfFieldFocus, 1.); - setFeature(qglDepthOfFieldDiaphragm, 8.); - hoverHalo_ = selectionHalo_ = true; - fogEnabled_ = is_init = shaders_bind = changed_ = false; - rmode = ObjectBase::Fill; -// sel_pen = QPen(Qt::black, 1, Qt::DashLine); -// sel_brush = QBrush(QColor(170, 100, 255, 120)); - scene_ = new Scene(); - connect(scene_, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged())); - connect(scene_, SIGNAL(__destroyed()), this, SLOT(__destroyed())); - connect(scene_, SIGNAL(__objectDeleted(ObjectBase*)), this, SLOT(__objectDeleted(ObjectBase*))); - default_camera = new Camera(); - default_camera->setPos(QVector3D(2, 2, 2)); - default_camera->setAim(QVector3D()); - camera_ = default_camera; -// qDebug() << camera_->aim(); - default_camera->setName("Camera"); - emit cameraPosChanged(default_camera->pos()); - //camera().aim_ = camera().pos_; - ktm_.restart(); - - //Mesh * m = Primitive::torus(100, 40, 1., 0.4, 360); - Mesh * m = Primitive::cube(10, 10, 10); - m->flipNormals(); - //QMatrix4x4 mat; - //mat.rotate(90, 0,1,0); - //mat.translate(0, 0, 2); - //mat.rotate(180, 1,0,0); - //m->transformPoints(mat); - ObjectBase * o = new ObjectBase(m); - o->setColor(Qt::cyan); - scene()->addObject(o); - delete m; - -} - - -QGLView::~QGLView() { - deleting_ = true; - stop(); - scene_->clear(); - delete scene_; - delete default_camera; -} - - -void QGLView::stop() { - if (timer) killTimer(timer); -} - - -void QGLView::start(float freq) { - timer = startTimer(freq <= 0.f ? 0 : int(1000.f / freq)); -} - - -QList QGLView::selectedLights() const { - QList ret; - ObjectBaseList sol = scene_->selectedObjects(); - foreach (ObjectBase * o, sol) - if (o->type() == ObjectBase::glLight) - ret << (Light*)o; - return ret; -} - - -QList QGLView::selectedCameras() const { - QList ret; - ObjectBaseList sol = scene_->selectedObjects(); - foreach (ObjectBase * o, sol) - if (o->type() == ObjectBase::glCamera) - ret << (Camera*)o; - return ret; -} - - - -void QGLView::resizeEvent(QResizeEvent * e) { - renderLater(); - mouse.resize(); -} - - -void QGLView::timerEvent(QTimerEvent *) { - renderNow(); - //if (ktm_.elapsed() < QApplication::keyboardInputInterval()) return; - Qt::KeyboardModifiers km = QApplication::keyboardModifiers(); - foreach (int i, keys_) - emit keyEvent((Qt::Key)i, km); -} - - -void QGLView::render() { - resizeGL(width(), height()); - emit glBeginPaint(); - renderer_.mouse_pos = mapFromGlobal(QCursor::pos()); - renderer_.renderScene(); - emit glEndPaint(); - fps_tm += time.elapsed(); - time.restart(); - fps_cnt++; - if (fps_tm < 1000.) return; - fps_ = fps_cnt / fps_tm * 1000.; - fps_tm = 0.; - fps_cnt = 0; -} - - -void QGLView::initialize() { - checkCaps(); - glPixelStorei(GL_PACK_ALIGNMENT, 1); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glDisable(GL_MULTISAMPLE); - glDisable(GL_BLEND); - glEnable(GL_TEXTURE_2D); - glEnable(GL_TEXTURE_CUBE_MAP); - glEnable(GL_TEXTURE_MAX_ANISOTROPY_EXT); - glEnable(GL_CULL_FACE); - glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); - glCullFace(GL_BACK); - renderer_.reloadShaders(); - renderer_.init(width(), height()); - is_init = true; - need_init_ = false; - emit glInitializeDone(); -} - - -void QGLView::checkCaps() { - glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropic); - shaders_supported = QOpenGLShaderProgram::hasOpenGLShaderPrograms(); -} - - -void QGLView::__destroyed() { - renderer_.rend_mat.mat_thumbnails.clear(); - mouse.hov_objects.clear(); -} - - -void QGLView::__objectDeleted(ObjectBase * o) { - if (o == camera_) - setDefaultCamera(); -} - - -void QGLView::resizeGL(int width, int height) { - if (!is_init) return; - if (width <= 0 || height <= 0) return; - if (prev_size == QSize(width, height)) return; - prev_size = QSize(width, height); - aspect = float(width) / float(height); - renderer_.resize(width, height); - //qDebug() << "resize" << width << height; - iaspect = (aspect == 0.f) ? 0. : 1 / aspect; - glViewport(0, 0, width, height); - emit glResize(width, height); -} - - -void QGLView::keyPressEvent(QKeyEvent * e) { - emit glKeyPressEvent(e); - if (e->key() > 0) keys_.insert(e->key()); - if (e->key() == Qt::Key_F11) { - emit doubleClick(); - } -} - - -void QGLView::keyReleaseEvent(QKeyEvent * e) { - emit glKeyReleaseEvent(e); - keys_.remove(e->key()); -} - - -void QGLView::focusOutEvent(QFocusEvent *) { - keys_.clear(); -} - - -void QGLView::focusOn(const Box3D & bb) { - if (bb.isEmpty() || !camera()) return; - double size = qMax(qMax(bb.width, bb.length), bb.height); - camera()->setAim(bb.center()); - camera()->flyToDistance(size * 1.25); -} - - -QByteArray QGLView::saveCamera() { - ChunkStream cs; - const Camera * c = camera(); - cs.add(1, c->pos()).add(2, c->aim()).add(3, c->rotation()).add(4, c->FOV()); - return cs.data(); -} - - -void QGLView::restoreCamera(const QByteArray & ba) { - if (ba.isEmpty()) return; - Camera * c = camera(); - QVector3D pos(c->pos()), aim(c->aim()), ang(c->rotation()); - float fov(c->FOV()); - ChunkStream cs(ba); - cs.readAll(); - cs.get(1, pos).get(2, aim).get(3, ang).get(4, fov); - camera()->setPos(pos); - camera()->setAim(aim); - camera()->setAngles(ang); - camera()->setFOV(fov); -} - - -QByteArray QGLView::saveFeatures() { - QByteArray ba; - QDataStream ds(&ba, QIODevice::WriteOnly); - ds << features_; - return ba; -} - - -void QGLView::restoreFeatures(const QByteArray & ba) { - QHash f; - QDataStream ds(ba); - ds >> f; - features_ = f; -} diff --git a/qglengine/qglview.h b/qglengine/qglview.h deleted file mode 100644 index 8f4d40e..0000000 --- a/qglengine/qglview.h +++ /dev/null @@ -1,293 +0,0 @@ -/* - QGLView - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef QGLVIEW_H -#define QGLVIEW_H - -#include "openglwindow.h" -#include "glframebuffer.h" -#include "glprimitives.h" -#include "glcamera.h" -#include "glrendererbase.h" -#include "glscene.h" -#include "renderer.h" -#include "mouse_controller.h" -#include -#include - - -class QGLView: public OpenGLWindow -{ - friend class MouseController; - friend class GLRendererBase; - friend class TextureManager; - friend class ObjectBase; - friend class Scene; - friend class RendererBase; - friend class Renderer; - friend class RendererMaterial; - friend class RendererService; - friend class RendererSelection; - friend class TonemappingProc; - Q_OBJECT - Q_PROPERTY (QColor backColor READ backColor WRITE setBackColor) - Q_PROPERTY (float lineWidth READ lineWidth WRITE setLineWidth) - Q_PROPERTY (float FOV READ FOV WRITE setFOV) - Q_PROPERTY (float depthStart READ depthStart WRITE setDepthStart) - Q_PROPERTY (float gamma READ gamma WRITE setGamma) - Q_PROPERTY (bool autoExposure READ autoExposure WRITE setAutoExposure) - Q_PROPERTY (QColor ambientColor READ ambientColor WRITE setAmbientColor) - Q_PROPERTY (QColor fogColor READ fogColor WRITE setFogColor) - Q_PROPERTY (bool fogEnabled READ isFogEnabled WRITE setFogEnabled) - Q_PROPERTY (float fogDensity READ fogDensity WRITE setFogDensity) - Q_PROPERTY (float fogDecay READ fogDecay WRITE setFogDecay) - Q_PROPERTY (int renderMode READ renderMode WRITE setRenderMode) - Q_PROPERTY (bool grabMouse READ isGrabMouseEnabled WRITE setGrabMouseEnabled) - Q_PROPERTY (bool mouseRotate READ isMouseRotateEnabled WRITE setMouseRotateEnabled) - Q_PROPERTY (bool mouseSelection READ isMouseSelectionEnabled WRITE setMouseSelectionEnabled) - Q_PROPERTY (bool cameraOrbit READ isCameraOrbit WRITE setCameraOrbit) - Q_PROPERTY (bool hoverHalo READ isHoverHaloEnabled WRITE setHoverHaloEnabled) - Q_PROPERTY (QColor hoverHaloColor READ hoverHaloColor WRITE setHoverHaloColor) - Q_PROPERTY (float hoverHaloFillAlpha READ hoverHaloFillAlpha WRITE setHoverHaloFillAlpha) - Q_PROPERTY (bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled) - Q_PROPERTY (QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor) - Q_PROPERTY (float selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha) - Q_PROPERTY (Qt::MouseButton selectionButton READ selectionButton WRITE setSelectionButton) - Q_PROPERTY (Qt::KeyboardModifier selectionModifier READ selectionModifier WRITE setSelectionModifier) - Q_PROPERTY (Scene::SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) - -public: - QGLView(); - virtual ~QGLView(); - - enum CameraLightMode { - clmOff, - clmAuto, - clmOn, - }; - - enum Feature { - qglFXAA, - qglAnisotropicLevel, - qglEyeAccomodationEnabled, - qglEyeAccomodationTime, - qglEyeAccomodationMaxSpeed, - qglBloomEnabled, - qglBloomThreshold, - qglBloomFactor, - qglBloomRadius, - qglMotionBlurEnabled, - qglMotionBlurFactor, - qglMotionBlurSteps, - qglShadowsEnabled, - qglShadowsMapSize, - qglShadowsSoftEnabled, - qglReflectionsEnabled, - qglReflectionsBlur, - qglSSAOEnabled, - qglSSAORadius, - qglDepthOfFieldEnabled, - qglDepthOfFieldAutoFocusEnabled, - qglDepthOfFieldAutoFocusSpeed, - qglDepthOfFieldFocus, - qglDepthOfFieldDiaphragm - }; - - Q_ENUM(CameraLightMode) - - void stop(); - void start(float freq = 60.); - - QColor backColor() const {return backColor_;} - float lineWidth() const {return lineWidth_;} - float FOV() const {return camera()->fov_;} - float depthStart() const {return camera()->depth_start;} - float currentFPS() const {return fps_;} - float gamma() const {return renderer_.gamma_;} - bool autoExposure() const {return renderer_.tone_proc.enabled;} - int maxAnisotropicLevel() const {return max_anisotropic;} - QString environmentMapFile() const {return renderer_.tex_env.fileHDR();} - - QColor ambientColor() const {return ambientColor_;} - QColor fogColor() const {return fogColor_;} - float fogDensity() const {return fogDensity_;} - float fogDecay() const {return fogDecay_;} - bool isFogEnabled() const {return fogEnabled_;} - bool isLightEnabled() const {return lightEnabled_;} - bool isGrabMouseEnabled() const {return mouse.isGrabMouseEnabled();} - bool isMouseRotateEnabled() const {return mouse.isMouseRotateEnabled();} - bool isMouseSelectionEnabled() const {return mouse.isMouseSelectionEnabled();} - bool isCameraOrbit() const {return mouse.isCameraOrbit();} - bool isHoverHaloEnabled() const {return hoverHalo_;} - QColor hoverHaloColor() const {return hoverHaloColor_;} - float hoverHaloFillAlpha() const {return hoverHaloFill_;} - bool isSelectionHaloEnabled() const {return selectionHalo_;} - QColor selectionHaloColor() const {return selectionHaloColor_;} - float selectionHaloFillAlpha() const {return selectionHaloFill_;} - - QVariant feature(Feature f) const {return features_.value(int(f));} - QVariant setFeature(Feature f, const QVariant & value) {QVariant ret = features_.value(int(f)); features_[int(f)] = value; return ret;} - bool isFeatureEnabled(Feature f) const {return features_[int(f)].toBool();} - - int renderMode() const {return (int)rmode;} - void setRenderMode(int mode) {rmode = (ObjectBase::RenderMode)mode;} - - bool isServiceMode() const {return renderer_.edit_mode;} - void setServiceMode(bool yes) {renderer_.edit_mode = yes;} - - - Scene::SelectionMode selectionMode() const {return scene_->selectionMode();} - Qt::MouseButton selectionButton() const {return mouse.selectionButton();} - Qt::KeyboardModifier selectionModifier() const {return mouse.selectionModifier();} - - void setSelectionMode(Scene::SelectionMode m) {scene_->setSelectionMode(m);} - void setSelectionButton(Qt::MouseButton v) {mouse.setSelectionButton(v);} - void setSelectionModifier(Qt::KeyboardModifier v) {mouse.setSelectionModifier(v);} - - void selectObject(ObjectBase * o, bool add_to_selection = false) {scene_->selectObject(o, add_to_selection);} - void clearSelection() {scene_->clearSelection();} - ObjectBaseList selectedObjects(bool top_only = false) const {return scene_->selectedObjects(top_only);} - QList selectedLights() const; - QList selectedCameras() const; - ObjectBase * selectedObject() const {return scene_->selectedObject();} - - TextureManager * textureManager() {return renderer_.textures_manager;} - void reloadTextures() {renderer_.markReloadTextures();} - - Scene * scene() {return scene_;} - void focusOn(const Box3D & bb); - void setCameraLightMode(CameraLightMode m) {renderer_.setCameraLightMode(m);} - CameraLightMode cameraLightMode() const {return (CameraLightMode)renderer_.cameraLightMode();} - - Camera * camera() {return camera_;} - const Camera * camera() const {return camera_;} - void setCamera(Camera * camera) {camera_ = camera;} - void setDefaultCamera() {camera_ = default_camera;} - QByteArray saveCamera(); - void restoreCamera(const QByteArray & ba); - QByteArray saveFeatures(); - void restoreFeatures(const QByteArray & ba); - - QImage materialThumbnail(Material * m) {return renderer_.materialThumbnail(m);} - void setCurrentAction(RendererService::HandleAction ha) {renderer_.rend_service.setCurrentAction(ha);} - void setContextActions(QList al) {context_menu.clear(); context_menu.addActions(al);} - - GLfloat aspect, iaspect; - Renderer renderer_; - -protected: - void render(); - void resizeEvent(QResizeEvent * e); - - void timerEvent(QTimerEvent * ); - void initialize(); - void resizeGL(int width, int height); - void mousePressEvent(QMouseEvent * e) {mouse.mousePressEvent(e);} - void mouseMoveEvent(QMouseEvent * e) {mouse.mouseMoveEvent(e);} - void mouseReleaseEvent(QMouseEvent * e) {mouse.mouseReleaseEvent(e);} - void wheelEvent(QWheelEvent * e) {mouse.wheelEvent(e);} - void mouseDoubleClickEvent(QMouseEvent * e) {mouse.mouseDoubleClickEvent(e);} - void leaveEvent(QEvent * ); - - void keyPressEvent(QKeyEvent * e); - void keyReleaseEvent(QKeyEvent * e); - void focusOutEvent(QFocusEvent *); - - void checkCaps(); - -private: - void processKeys(); - bool setupViewport(); - - Scene * scene_; - Camera * camera_, * default_camera; - MouseController mouse; - QMenu context_menu; - QSet keys_; - QColor backColor_, fogColor_, ambientColor_, hoverHaloColor_, selectionHaloColor_; - QTime time, ktm_; - GLint max_anisotropic, max_texture_chanels; - ObjectBase::RenderMode rmode; - GLRendererBase::RenderingParameters start_rp; - QHash features_; - QSize prev_size; - float lineWidth_; - float fps_, fps_tm, fogDensity_, fogDecay_; - float hoverHaloFill_, selectionHaloFill_, m_motionBlurFactor; - int timer, fps_cnt, sh_id_loc, deleting_; - bool is_first_draw, is_init, fogEnabled_, lightEnabled_; - bool shaders_supported, changed_, need_init_; - bool hoverHalo_, selectionHalo_, shaders_bind; - -private slots: - void __destroyed(); - void __objectDeleted(ObjectBase * o); - -public slots: - void setBackColor(const QColor & arg) {backColor_ = arg;} - void setLineWidth(const float & arg) {lineWidth_ = arg;} - void setFOV(const float & arg) {camera()->fov_ = arg;} - void setDepthStart(const float & arg) {camera()->depth_start = arg;} - void setGamma(const float & arg) {renderer_.gamma_ = arg;} - void setAutoExposure(bool arg) {renderer_.tone_proc.enabled = arg;} - void setAmbientColor(const QColor & arg) {ambientColor_ = arg;} - void setEnvironmentMapFile(QString file) {renderer_.tex_env.setFileHDR(file); renderer_.recreateMaterialThumbnails(true);} - void setFogColor(const QColor & arg) {fogColor_ = arg;} - void setFogDensity(const float & arg) {fogDensity_ = arg;} - void setFogDecay(const float & arg) {fogDecay_ = arg;} - void setFogEnabled(const bool & arg) {fogEnabled_ = arg;} - void setLightEnabled(const bool & arg) {lightEnabled_ = arg;} - void setGrabMouseEnabled(const bool & arg) {mouse.setGrabMouseEnabled(arg);} - void setMouseRotateEnabled(const bool & arg) {mouse.setMouseRotateEnabled(arg);} - void setMouseSelectionEnabled(const bool & arg) {mouse.setMouseSelectionEnabled(arg);} - void setCustomMouseMove(const bool & arg) {mouse.setCustomMouseMove(arg);} - void setCameraOrbit(const bool & arg) {mouse.setCameraOrbit(arg);} - void setHoverHaloEnabled(const bool & arg) {hoverHalo_ = arg;} - void setHoverHaloColor(const QColor & arg) {hoverHaloColor_ = arg;} - void setHoverHaloFillAlpha(const float & arg) {hoverHaloFill_ = arg;} - void setSelectionHaloEnabled(const bool & arg) {selectionHalo_ = arg;} - void setSelectionHaloColor(const QColor & arg) {selectionHaloColor_ = arg;} - void setSelectionHaloFillAlpha(const float & arg) {selectionHaloFill_ = arg;} - - void reloadShaders() {renderer_.reloadShaders();} - -signals: - void glBeginPaint(); - void glEndPaint(); - void glKeyPressEvent(QKeyEvent * e); - void glKeyReleaseEvent(QKeyEvent * e); - void glMousePressEvent(QMouseEvent * e); - void glMouseMoveEvent(QMouseEvent * e); - void glMouseReleaseEvent(QMouseEvent * e); - void glWheelEvent(QWheelEvent * e); - void glResize(int, int); - void glInitializeDone(); - void cameraPosChanged(QVector3D pos); - void keyEvent(Qt::Key key, Qt::KeyboardModifiers mod); - void customMouseMoveEvent(QPoint curpos, QPoint lastpos, Qt::MouseButtons buttons); - - void hoverChanged(ObjectBase * cur, ObjectBase * prev); - void selectionChanged(); - void objectsPositionChanged(); - void materialsChanged(); - void materialThumbnailCreated(Material*); - void doubleClick(); - -}; - -#endif // QGLVIEW_H diff --git a/qglengine/qglview.qrc b/qglengine/qglview.qrc deleted file mode 100644 index e67f617..0000000 --- a/qglengine/qglview.qrc +++ /dev/null @@ -1,46 +0,0 @@ - - - coeffs_brdf.png - icons/add-type-camera.png - icons/add-type-geo.png - icons/add-type-light.png - icons/add-type-empty.png - icons/collapse.png - icons/expand.png - icons/edit-rename.png - icons/alpha.png - icons/application-exit.png - icons/configure.png - icons/dialog-close.png - icons/document-edit.png - icons/document-import.png - icons/document-new.png - icons/document-open.png - icons/document-save.png - icons/document-save-all.png - icons/edit-clear.png - icons/edit-clear-locationbar-rtl.png - icons/edit-copy.png - icons/edit-delete.png - icons/edit-find.png - icons/edit-paste.png - icons/go-jump.png - icons/go-top.png - icons/layer-visible-on.png - icons/layer-visible-off.png - icons/light-+.png - icons/list-add.png - icons/object-flip-horizontal.png - icons/object-flip-vertical.png - icons/picker.png - icons/qglview.png - icons/transform-move.png - icons/transform-rotate.png - icons/transform-scale.png - icons/type-camera.png - icons/type-geo.png - icons/type-light.png - icons/type-empty.png - icons/view-refresh.png - - diff --git a/qglengine/qglview_test/main.cpp b/qglengine/qglview_test/main.cpp deleted file mode 100644 index eb43d61..0000000 --- a/qglengine/qglview_test/main.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - QGLViewWindow - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include -#include -#include -#include "qglview_window.h" - -int main(int argc, char ** argv) { - QApplication a(argc, argv); - a.setAttribute(Qt::AA_UseHighDpiPixmaps, true); - QGLViewWindow w; - w.show(); - QStringList al(a.arguments()); - al.pop_front(); - foreach (QString s, al) - w.loadFile(s); - return a.exec(); -} diff --git a/qglengine/qglview_test/qglview_window.cpp b/qglengine/qglview_test/qglview_window.cpp deleted file mode 100644 index a6ac505..0000000 --- a/qglengine/qglview_test/qglview_window.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/* - QGLViewWindow - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "qglview_window.h" -#include "renderer.h" -#include "glwidget.h" -#include "gltexture_manager.h" -#include -#include -#include -#include "qad_types.h" - - -QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLViewWindow() { - setupUi(this); - session.setFile("session_qglview_test.conf"); - session.addEntry(this); - - extensions = "All(" + supportedFormats().join(" ") + " *.qgl)"; - extensions += ";;QGLEngine(*.qgl)"; - - //view->view()->camera()->setPos(QVector3D(2, 2, 2)); - //view->view()->camera()->setAim(QVector3D()); - //view->view()->camera()->flyToDistance(2.); -// view->setFrameShape(QFrame::NoFrame); - view->view()->setMouseRotateEnabled(true); - view->view()->setMouseSelectionEnabled(true); - view->view()->setSelectionHaloEnabled(true); - view->view()->setHoverHaloEnabled(true); - view->view()->setBackColor(Qt::lightGray); - view->view()->setDepthStart(0.1); - view->view()->setSelectionMode(Scene::smMultiSelection); - - - groupShadows->setChecked(view->view()->isFeatureEnabled(QGLView::qglShadowsEnabled)); - groupEyeAccomodation->setChecked(view->view()->isFeatureEnabled(QGLView::qglEyeAccomodationEnabled)); - groupBloom->setChecked(view->view()->isFeatureEnabled(QGLView::qglBloomEnabled)); - groupMotionBlur->setChecked(view->view()->isFeatureEnabled(QGLView::qglMotionBlurEnabled)); - groupReflections->setChecked(view->view()->isFeatureEnabled(QGLView::qglReflectionsEnabled)); - checkSoftShadows->setChecked(view->view()->isFeatureEnabled(QGLView::qglShadowsSoftEnabled)); - groupSSAO->setChecked(view->view()->isFeatureEnabled(QGLView::qglSSAOEnabled)); - spinAccom->setValue(view->view()->feature(QGLView::qglEyeAccomodationTime).toDouble()); - spinAccomMS->setValue(view->view()->feature(QGLView::qglEyeAccomodationMaxSpeed).toDouble()); - checkReflectionsBlur->setChecked(view->view()->isFeatureEnabled(QGLView::qglReflectionsBlur)); - spinShadowmapSize->setValue(view->view()->feature(QGLView::qglShadowsMapSize).toInt()); - spinMotionBlurFactor->setValue(view->view()->feature(QGLView::qglMotionBlurFactor).toDouble()); - spinMotionBlurSteps->setValue(view->view()->feature(QGLView::qglMotionBlurSteps).toInt()); - spinBloomFactor->setValue(view->view()->feature(QGLView::qglBloomFactor).toDouble()); - spinBloomRadius->setValue(view->view()->feature(QGLView::qglBloomRadius).toInt()); - spinBloomThreshold->setValue(view->view()->feature(QGLView::qglBloomThreshold).toDouble()); - spinSSAORadius->setValue(view->view()->feature(QGLView::qglSSAORadius).toInt()); - groupDOF->setChecked(view->view()->isFeatureEnabled(QGLView::qglDepthOfFieldEnabled)); - checkDOFAutoFocus->setChecked(view->view()->isFeatureEnabled(QGLView::qglDepthOfFieldAutoFocusEnabled)); - spinDOFFocus->setValue(view->view()->feature(QGLView::qglDepthOfFieldFocus).toDouble()); - spinDOFDiaphragm->setValue(view->view()->feature(QGLView::qglDepthOfFieldDiaphragm).toDouble()); - spinDOFSpeed->setValue(view->view()->feature(QGLView::qglDepthOfFieldAutoFocusSpeed).toDouble()); - - view->view()->start(-1); - startTimer(1000/60); - - connect(view->view(), SIGNAL(keyEvent(Qt::Key, Qt::KeyboardModifiers)), this, SLOT(view_keyEvent(Qt::Key, Qt::KeyboardModifiers))); - //connect(matEditor, SIGNAL(changed()), this, SLOT(materialChanged())); - sceneTree->assignQGLView(view->view()); - matEditor->assignQGLView(view->view()); - objectEditor->assignQGLView(view->view()); - primitiveEditor->assignQGLView(view->view()); - viewEditor->assignQGLView(view->view()); - - session.load(); - - //loadFile("axis.DAE.qgl"); - //matEditor->setMaterial(const_cast(view->view()->scene()->rootObject()->child(0))->material()); - /*Scene * sc = loadScene("truck.obj"); - //view->view()->scene()->addScene(sc); - sc->rootObject()->moveY(-8); - for (int i = 0; i < 7; ++i) { - sc->rootObject()->moveY(2); - view->view()->scene()->addScene(sc); - } - //view->view()->scene()->dump(); - delete sc;*/ -} - - -QGLViewWindow::~QGLViewWindow() { - session.save(); - //delete ps; -} - - -void QGLViewWindow::changeEvent(QEvent * e) { - QMainWindow::changeEvent(e); - if (e->type() == QEvent::LanguageChange) { - retranslateUi(this); - return; - } -} - - -void QGLViewWindow::timerEvent(QTimerEvent * ) { - //static double t = 0.; - //((RendererSimple*)(view->view()->renderer()))->mpos = view->view()->mapFromGlobal(QCursor::pos()); - statusBar()->showMessage(QString("FPS: %1").arg(QString::number(view->view()->currentFPS(), 'f', 2))); -} - - -void QGLViewWindow::loadFile(const QString & path, bool import) { - prev_path = path; - QApplication::setOverrideCursor(Qt::WaitCursor); - QFileInfo fi(path); - Scene * s = nullptr; - if (fi.suffix().toLower() == "qgl") s = loadFromQGLFile(path); - else s = loadScene(path); - QApplication::restoreOverrideCursor(); - if (!s) { - QMessageBox::critical(this, "Import", "Can`t load " + path + "!"); - return; - } - s->setName(fi.baseName()); - if (import) view->scene()->addScene(s); - else { - TextureManager::clearSearchPathes(); - view->scene()->assignFrom(s); - view->view()->focusOn(view->scene()->boundingBox()); - } - TextureManager::addSearchPath(fi.absoluteDir().path()); - delete s; -} - - -void QGLViewWindow::on_actionReset_triggered() { - ///view->view()->removeObject(axis, false); - view->view()->scene()->clear(); - ///view->view()->addObject(axis); -} - - -void QGLViewWindow::on_actionImport_triggered() { - QStringList fl = QFileDialog::getOpenFileNames(this, "Select files", prev_path, extensions); - if (fl.isEmpty()) return; - prev_path = fl.back(); - foreach (QString f, fl) - loadFile(f, true); -} - - -void QGLViewWindow::on_actionSave_triggered() { - QString f = QFileDialog::getSaveFileName(this, "Select file", prev_path, "QGLView(*.qgl)"); - if (f.isEmpty()) return; - if (f.right(4).toLower() != ".qgl") - f += ".qgl"; - prev_path = f; - QApplication::setOverrideCursor(Qt::WaitCursor); - saveToQGLFile(f, view->scene()); - QApplication::restoreOverrideCursor(); -} - - -void QGLViewWindow::on_actionSaveSelected_triggered() { - ObjectBase * sel_obj = view->view()->selectedObject(); - if (!sel_obj) return; - QString f = QFileDialog::getSaveFileName(this, "Select file", prev_path, "QGLView(*.qgl)"); - if (f.isEmpty()) return; - if (f.right(4).toLower() != ".qgl") - f += ".qgl"; - prev_path = f; - QApplication::setOverrideCursor(Qt::WaitCursor); - ///saveToQGLFile(f, sel_obj); - QApplication::restoreOverrideCursor(); -} - - -void QGLViewWindow::on_actionOpen_triggered() { - QString f = QFileDialog::getOpenFileName(this, "Select file", prev_path, extensions); - if (f.isEmpty()) return; - prev_path = f; - loadFile(f); -} - - -void QGLViewWindow::view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m) { - //qDebug() << k; - double spd = 0.2; - if (m.testFlag(Qt::ShiftModifier)) - spd = 0.5; - switch (k) { - case Qt::Key_W: view->view()->camera()->moveForward(spd); break; - case Qt::Key_S: view->view()->camera()->moveBackward(spd); break; - case Qt::Key_A: view->view()->camera()->moveLeft(spd); break; - case Qt::Key_D: view->view()->camera()->moveRight(spd); break; - default: break; - } -} - - -void QGLViewWindow::on_actionArrow_triggered(bool on) { - actionArrow ->setChecked(true); - actionMove ->setChecked(false); - actionRotate->setChecked(false); - actionScale ->setChecked(false); - view->view()->setCurrentAction(RendererService::haNoAction); -} - - -void QGLViewWindow::on_actionMove_triggered(bool on) { - actionArrow ->setChecked(false); - actionMove ->setChecked(true); - actionRotate->setChecked(false); - actionScale ->setChecked(false); - view->view()->setCurrentAction(RendererService::haMove); -} - - -void QGLViewWindow::on_actionRotate_triggered(bool on) { - actionArrow ->setChecked(false); - actionMove ->setChecked(false); - actionRotate->setChecked(true); - actionScale ->setChecked(false); - view->view()->setCurrentAction(RendererService::haRotate); -} - - -void QGLViewWindow::on_actionScale_triggered(bool on) { - actionArrow ->setChecked(false); - actionMove ->setChecked(false); - actionRotate->setChecked(false); - actionScale ->setChecked(true); - view->view()->setCurrentAction(RendererService::haScale); -} - - -#include "glcubemap.h" -void QGLViewWindow::on_pushButton_3_clicked() { - QString f = QFileDialog::getOpenFileName(this, "Select file", "", "*"); - if (f.isEmpty()) return; -} diff --git a/qglengine/qglview_test/qglview_window.h b/qglengine/qglview_test/qglview_window.h deleted file mode 100644 index 304353f..0000000 --- a/qglengine/qglview_test/qglview_window.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - QGLViewWindow - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef QGLVIEWWINDOW_H -#define QGLVIEWWINDOW_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "ui_qglview_window.h" -#include "formats/loader_qgl.h" -#include "formats/loader_assimp.h" -#include "session_manager.h" -//#include "renderer_rt.h" -#include "qglview.h" -#include "ui_qglview_window.h" - - -class QGLViewWindow: public QMainWindow, public Ui::QGLViewWindow -{ - Q_OBJECT -public: - QGLViewWindow(QWidget * parent = 0); - ~QGLViewWindow(); - - void loadFile(const QString & path, bool import = false); - -private: - // Qt`s overloaded - void changeEvent(QEvent * e); - void timerEvent(QTimerEvent * ); - - QString extensions; - QTranslator translator; - QString prev_path; - //GLPrimitiveCube * box; - Material m; - SessionManager session; - bool isChanged; - -private slots: - void on_groupShadows_clicked(bool val) {view->view()->setFeature(QGLView::qglShadowsEnabled, val);} - void on_groupEyeAccomodation_clicked(bool val) {view->view()->setFeature(QGLView::qglEyeAccomodationEnabled, val);} - void on_groupBloom_clicked(bool val) {view->view()->setFeature(QGLView::qglBloomEnabled, val);} - void on_groupMotionBlur_clicked(bool val) {view->view()->setFeature(QGLView::qglMotionBlurEnabled, val);} - void on_groupReflections_clicked(bool val) {view->view()->setFeature(QGLView::qglReflectionsEnabled, val);} - void on_checkSoftShadows_clicked(bool val) {view->view()->setFeature(QGLView::qglShadowsSoftEnabled, val);} - void on_groupSSAO_clicked(bool val) {view->view()->setFeature(QGLView::qglSSAOEnabled, val);} - void on_groupDOF_clicked(bool val) {view->view()->setFeature(QGLView::qglDepthOfFieldEnabled, val);} - void on_checkDOFAutoFocus_clicked(bool val) {view->view()->setFeature(QGLView::qglDepthOfFieldAutoFocusEnabled, val);} - void on_spinDOFFocus_valueChanged(double val) {view->view()->setFeature(QGLView::qglDepthOfFieldFocus, val);} - void on_spinDOFDiaphragm_valueChanged(double val) {view->view()->setFeature(QGLView::qglDepthOfFieldDiaphragm, val);} - void on_spinDOFSpeed_valueChanged(double val) {view->view()->setFeature(QGLView::qglDepthOfFieldAutoFocusSpeed, val);} - void on_spinAccom_valueChanged(double val) {view->view()->setFeature(QGLView::qglEyeAccomodationTime, val);} - void on_spinAccomMS_valueChanged(double val) {view->view()->setFeature(QGLView::qglEyeAccomodationMaxSpeed, val);} - void on_checkReflectionsBlur_clicked(bool val) {view->view()->setFeature(QGLView::qglReflectionsBlur, val);} - void on_spinShadowmapSize_valueChanged(double val) {view->view()->setFeature(QGLView::qglShadowsMapSize, val);} - void on_spinMotionBlurFactor_valueChanged(double val) {view->view()->setFeature(QGLView::qglMotionBlurFactor, val);} - void on_spinMotionBlurSteps_valueChanged(int val) {view->view()->setFeature(QGLView::qglMotionBlurSteps, val);} - void on_spinBloomFactor_valueChanged(double val) {view->view()->setFeature(QGLView::qglBloomFactor, val);} - void on_spinBloomRadius_valueChanged(int val) {view->view()->setFeature(QGLView::qglBloomRadius, val);} - void on_spinBloomThreshold_valueChanged(double val) {view->view()->setFeature(QGLView::qglBloomThreshold, val);} - void on_spinSSAORadius_valueChanged(int val) {view->view()->setFeature(QGLView::qglSSAORadius, val);} - - void on_actionExit_triggered() {close();} - void on_actionReset_triggered(); - void on_actionImport_triggered(); - void on_actionSave_triggered(); - void on_actionSaveSelected_triggered(); - void on_actionOpen_triggered(); - - void view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m); - - void on_pushButton_2_clicked() {view->view()->reloadShaders();} - - void on_actionArrow_triggered(bool on); - void on_actionMove_triggered(bool on); - void on_actionRotate_triggered(bool on); - void on_actionScale_triggered(bool on); - - void on_colorFogBack_colorChanged(const QColor & v) {view->view()->setFogColor(v);} - void on_spinFogDensity_valueChanged(double v) {view->view()->setFogDensity(v);} - void on_spinFogDecay_valueChanged(double v) {view->view()->setFogDecay(v);} - - void on_pushButton_3_clicked(); - -public slots: - -signals: - -private: - QMatrix4x4 cam_mat; - -}; - -#endif // QGLVIEWWINDOW_H diff --git a/qglengine/qglview_test/qglview_window.ui b/qglengine/qglview_test/qglview_window.ui deleted file mode 100644 index a9bde08..0000000 --- a/qglengine/qglview_test/qglview_window.ui +++ /dev/null @@ -1,978 +0,0 @@ - - - QGLViewWindow - - - - 0 - 0 - 1107 - 878 - - - - QGLView converter - - - - - - - Qt::Horizontal - - - - - 2 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - View - - - - - - 0 - - - - Common - - - - - - - - - - Features - - - - - - QFrame::NoFrame - - - true - - - - - 0 - 0 - 934 - 737 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Shadows - - - true - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - Shadowmap size - - - - - - - 16.000000000000000 - - - 2048.000000000000000 - - - 512.000000000000000 - - - 0 - - - 16.000000000000000 - - - 512.000000000000000 - - - true - - - - - - - Soft - - - true - - - - - - - - - - Bloom - - - true - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - Factror - - - - - - - 0.000000000000000 - - - 100.000000000000000 - - - 1.000000000000000 - - - 1 - - - 0.100000000000000 - - - 1.000000000000000 - - - false - - - - - - - 1.000000000000000 - - - 128.000000000000000 - - - 8.000000000000000 - - - 0 - - - 1.000000000000000 - - - 4.000000000000000 - - - false - - - - - - - Radius - - - - - - - Threshold - - - - - - - 0.000000000000000 - - - 1.000000000000000 - - - 0.900000000000000 - - - 2 - - - 0.050000000000000 - - - 0.100000000000000 - - - false - - - - - - - - - - Motion blur - - - true - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - Factror - - - - - - - Steps - - - - - - - 0.000000000000000 - - - 10000.000000000000000 - - - 1.000000000000000 - - - 1 - - - 0.100000000000000 - - - 1.000000000000000 - - - false - - - - - - - 1.000000000000000 - - - 128.000000000000000 - - - 8.000000000000000 - - - 0 - - - 1.000000000000000 - - - 4.000000000000000 - - - false - - - - - - - - - - Eye accomodation - - - true - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - Time - - - - - - - Max speed - - - - - - - 0.000000000000000 - - - 256.000000000000000 - - - 32.000000000000000 - - - true - - - - - - - 0.010000000000000 - - - 1.000000000000000 - - - 0.100000000000000 - - - 3 - - - 0.100000000000000 - - - 1.000000000000000 - - - true - - - - - - - - - - Depth of field - - - true - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - Diaphragm - - - - - - - Max speed - - - - - - - 0.100000000000000 - - - 1024.000000000000000 - - - 8.000000000000000 - - - true - - - - - - - 0.010000000000000 - - - 10.000000000000000 - - - 0.100000000000000 - - - 2 - - - 0.100000000000000 - - - 1.000000000000000 - - - true - - - - - - - Focus - - - - - - - 0.100000000000000 - - - 1000.000000000000000 - - - 1.000000000000000 - - - true - - - 999999.000000000000000 - - - - - - - Auto focus - - - - - - - - - - Reflections - - - true - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - Blur - - - - - - - - - - SSAO - - - true - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - Time - - - - - - - 0.000000000000000 - - - 16.000000000000000 - - - 5.000000000000000 - - - 0 - - - 1.000000000000000 - - - 4.000000000000000 - - - false - - - - - - - - - - Qt::Vertical - - - - 20 - 1 - - - - - - - - - - - - - - - - reload shaders - - - - - - - load HDR - - - - - - - Qt::Vertical - - - - 20 - 107 - - - - - - - - - Object - - - - - - - - - Qt::Vertical - - - - 20 - 1 - - - - - - - - - Material - - - - - - - - - - Primitives - - - - - - - - - - - - - - - 0 - 0 - - - - - - Scene - - - - - - - - - - - - - - toolBar - - - TopToolBarArea - - - false - - - - - - - - - - - 0 - 0 - 1107 - 24 - - - - - File - - - - - - - - - - - - - Scene - - - - - Mode - - - - - - - - - - - - - - toolBar_2 - - - TopToolBarArea - - - false - - - - - - :/icons/application-exit.png:/icons/application-exit.png - - - Exit - - - - - - :/icons/document-import.png:/icons/document-import.png - - - Import ... - - - Ctrl+I - - - - - - :/icons/document-open.png:/icons/document-open.png - - - Open ... - - - Ctrl+O - - - - - - :/icons/document-save-all.png:/icons/document-save-all.png - - - Save ... - - - Ctrl+S - - - - - - :/icons/document-new.png:/icons/document-new.png - - - Reset - - - Ctrl+N - - - - - - :/icons/document-save.png:/icons/document-save.png - - - Save selected ... - - - Save selected - - - Ctrl+Shift+S - - - - - true - - - true - - - Arrow - - - Ctrl+1 - - - - - true - - - - :/icons/transform-move.png:/icons/transform-move.png - - - Move - - - Ctrl+2 - - - - - true - - - - :/icons/transform-rotate.png:/icons/transform-rotate.png - - - Rotate - - - Ctrl+3 - - - - - true - - - - :/icons/transform-scale.png:/icons/transform-scale.png - - - Scale - - - Ctrl+4 - - - - - - SpinSlider - QWidget -
spinslider.h
-
- - GLWidget - QWidget -
glwidget.h
- 1 -
- - ObjectEditor - QWidget -
widgets/object_editor.h
- 1 -
- - SceneTree - QWidget -
scene_tree.h
- 1 -
- - MaterialsEditor - QWidget -
widgets/materials_editor.h
- 1 -
- - PrimitiveEditor - QWidget -
primitiveeditor.h
- 1 -
- - ViewEditor - QWidget -
view_editor.h
- 1 -
-
- - - - - - -
diff --git a/qglengine/renderer.cpp b/qglengine/renderer.cpp deleted file mode 100644 index 7aaec3c..0000000 --- a/qglengine/renderer.cpp +++ /dev/null @@ -1,382 +0,0 @@ -/* - QGL Renderer - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#define GL_GLEXT_PROTOTYPES -#include -#include "renderer.h" -#include "qglview.h" -#include "glmesh.h" -#include "gltexture_manager.h" -#include - -using namespace QGLEngineShaders; - - -Renderer::Renderer(QGLView * view_): RendererBase(view_), - fbo_ds (view_, QVector() << GL_RGBA16F << GL_RGBA32F << GL_RGBA16F << GL_RGBA16F << GL_RGBA16F), - fbo_out (view_, obrBuffersCount, false, GL_RGBA16F), - rend_mat(this), rend_service(this), rend_selection(this), tone_proc(this), tex_env(view_, 512) { - quad = Primitive::plane(2., 2.); - cam_light = new Light(); - cam_light->intensity = 0.75; - cam_light->setName("Camera_Light"); - - shader_files[srSelectionFill ] = "selection.glsl"; - shader_files[srSelectionHalo ] = "selection_halo.glsl"; - shader_files[srSelectionApply] = "selection_apply.glsl"; - shader_files[srSelectionFrame] = "selection_frame.glsl"; - - shader_files[srServiceFill ] = "service_fill.glsl"; - shader_files[srServiceFrame] = "service_frame.glsl"; - shader_files[srServiceLine ] = "service_line.glsl"; - - shader_files[srGeometryPass ] = "ds_geom.glsl"; - shader_files[srLightOmniPass] = "ds_light.glsl"; - shader_files[srLightSpotPass] = "ds_light.glsl"; shader_defines[srLightSpotPass] << "SPOT"; - shader_files[srFinalPass ] = "ds_final.glsl"; - shader_files[srTonemapPass ] = "ds_tonemap.glsl"; - - /*shaders << ShaderPair("FXAA", &shader_fxaa) - << ShaderPair("dsl_pass_0", &shader_ds_0) - << ShaderPair("dsl_pass_1", &shader_ds_1) - << ShaderPair("hdr", &shader_hdr) - << ShaderPair("downscale", &shader_small) - << ShaderPair("bloom_pass_0", &shader_bloom_0) - << ShaderPair("bloom_pass_1", &shader_bloom_1) - << ShaderPair("fbo_add", &shader_fbo_add) - << ShaderPair("motion_blur", &shader_motion_blur) - << ShaderPair("shadow", &shader_shadow) - << ShaderPair("ssr", &shader_ssr) - << ShaderPair("ssr_blur", &shader_ssr_blur) - << ShaderPair("ssr_merge", &shader_ssr_merge) - << ShaderPair("ssao_blur", &shader_ssao_blur) - << ShaderPair("ssao_merge", &shader_ssao_merge) - << ShaderPair("dof", &shader_dof);*/ - shader_fxaa = 0; - gamma_ = 1.; - edit_mode = need_init_shaders = true; - camera_light_mode = QGLView::clmAuto; -} - - -Renderer::~Renderer() { - delete quad; - delete cam_light; - qDeleteAll(shaders.values()); - if (shader_fxaa) delete shader_fxaa; -} - - -void Renderer::init(int width, int height) { - resize(width, height); - rend_mat.init(width, height); - rend_service.init(width, height); - rend_selection.init(width, height); - tone_proc.init(); - initQuad(quad); - initTextureArrays(); - initCoeffTextures(); - tex_env.init(); - need_init_shaders = true; -} - - -void Renderer::resize(int width, int height) { - rend_mat.resize(width, height); - rend_service.resize(width, height); - rend_selection.resize(width, height); - fbo_ds .resize(width, height); - fbo_out .resize(width, height); - tone_proc.resize(); -} - - -void Renderer::reloadShaders() { - QMapIterator it(shader_files); - QString dir = ":shaders/"; - while (it.hasNext()) { - it.next(); - loadShadersMulti(shaders[it.key()], dir + it.value(), true, shader_defines.value(it.key())); - } - loadShadersMulti(tone_proc.shader_sum, dir + "sum.glsl", false); - QStringList fxaa_defs; - fxaa_defs << "FXAA_PC 1" << "FXAA_GLSL_130 1" << "FXAA_QUALITY__PRESET 15"; - loadShaders(shader_fxaa, QStringList() << (dir + "fxaa.vert") << (dir + "fxaa.frag"), true, fxaa_defs); - need_init_shaders = true; - view->scene()->setLightsChanged(); - view->scene()->setTreeStructChanged(); - view->scene()->setMaterialsChanged(); -} - - -bool Renderer::bindShader(Renderer::ShaderRole role, QOpenGLShaderProgram ** ret) { - QOpenGLShaderProgram * prog = shaders.value(role); - if (ret) *ret = prog; - if (!prog) return false; - if (!prog->isLinked()) return false; - prog->bind(); - return true; -} - - -bool Renderer::bindShader(QOpenGLShaderProgram * sp) { - if (!sp) return true; - if (!sp->isLinked()) return true; - if (!sp->bind()) return false; - return true; -} - - -void Renderer::initShaders() { - if (!need_init_shaders) return; - need_init_shaders = false; - initUniformBuffer(shaders.value(srGeometryPass ), &buffer_materials , bpMaterials , "QGLMaterialData" ); - initUniformBuffer(shaders.value(srLightOmniPass), &buffer_materials , bpMaterials , "QGLMaterialData" ); - initUniformBuffer(shaders.value(srLightOmniPass), &buffer_lights , bpLightParameters, "QGLLightParameterData"); - initUniformBuffer(shaders.value(srLightOmniPass), &buffer_lights_pos, bpLightPositions , "QGLLightPositionData" ); - initUniformBuffer(shaders.value(srLightSpotPass), &buffer_materials , bpMaterials , "QGLMaterialData" ); - initUniformBuffer(shaders.value(srLightSpotPass), &buffer_lights , bpLightParameters, "QGLLightParameterData"); - initUniformBuffer(shaders.value(srLightSpotPass), &buffer_lights_pos, bpLightPositions , "QGLLightPositionData" ); - ShaderRole roles[] = {srLightOmniPass, srLightSpotPass}; - QOpenGLShaderProgram * prog = 0; - for (int p = 0; p < 2; ++p) { - if (!bindShader(roles[p], &prog)) continue; - for (int i = 0; i < 5; ++i) - prog->setUniformValue(QString("tex_%1").arg(i).toLatin1().constData(), i); - prog->setUniformValue("tex_coeffs[0]", (int)Renderer::dbrBuffersCount); - //prog->setUniformValue("tex_coeffs[1]", (int)Renderer::dbrBuffersCount+1); - prog->setUniformValue("tex_env", (int)Renderer::dbrBuffersCount+1); - } - if (bindShader(srFinalPass, &prog)) { - prog->setUniformValue("tex_g1" , 0); - prog->setUniformValue("tex_s_0", 1); - prog->setUniformValue("tex_s_1", 2); - prog->setUniformValue("tex_t_0", 3); - prog->setUniformValue("tex_t_1", 4); - } - if (bindShader(srGeometryPass, &prog)) { - setUniformMaps(prog); - } - if (bindShader(srTonemapPass, &prog)) { - prog->setUniformValue("tex_0", 0); - prog->setUniformValue("tex_sum", 1); - } -} - - -void Renderer::releaseShader() { - view->glUseProgram(0); -} - - -void Renderer::fillObjectsBuffer(const ObjectBaseList & ol, RenderPass pass) { - cur_objects_.resize(ol.size()); - for (int i = 0; i < ol.size(); ++i) { - Object & so(cur_objects_[i]); - ObjectBase * o = ol[i]; - if (o->material()) { - so.material = o->material()->_index; - so.color = QVector4D(1,1,1,1); - } else { - so.material = 0; - so.color = QColor2QVector(o->color_); - } - so.object_id = o->id_; - o->worldTransform().transposed().copyDataTo(so.modelmatrix); - //qDebug() << "load obj" << o->name() << o->worldTransform(); - } - //qDebug() << "fillObjectsBuffer" << ol.size(); - -} - - -void Renderer::renderObjects(Scene & scene, RenderPass pass) { - QOpenGLExtraFunctions * f = view; - QMapIterator it(scene.geometries_used[pass]); - bool emit_pos_change = false; - while (it.hasNext()) { - it.next(); - Mesh * mesh = it.key(); - if (mesh->isObjectsChanged(pass)) { - mesh->setObjectsChanged(pass, false); - emit_pos_change = true; - fillObjectsBuffer(it.value(), pass); - //qDebug() << "loadObjects" << pass << cur_objects_.size(); - mesh->loadObjects(f, cur_objects_, pass); - } - if (mesh->isSelectionChanged(pass) && edit_mode) { - mesh->setSelectionChanged(pass, false); - fillSelectionsBuffer(rend_selection.cur_selections_, it.value()); - //qDebug() << "fillSelectionsBuffer" << pass << rend_selection.cur_selections_.size(); - mesh->loadSelections(f, rend_selection.cur_selections_, pass); - } - //qDebug() << "draw" << pass << it.value().size(); - mesh->draw(f, it.value().size(), pass); - } - if (emit_pos_change) emit view->objectsPositionChanged(); -} - - -void Renderer::renderLight(int first_wr_buff, bool clear_only) { - QOpenGLShaderProgram * prog = 0; - Camera * cam = view->camera(); - for (int i = 0; i < 2; ++i) { - view->glActiveTexture(GL_TEXTURE0 + Renderer::dbrBuffersCount + i); - view->glBindTexture(GL_TEXTURE_2D, tex_coeff[i]); - } - fbo_ds.bindColorTextures(); - fbo_out.bind(); - tex_env.bind((int)Renderer::dbrBuffersCount+1); - //int ri = 1, wi = 0; - typedef QPair PassPair; - QVector passes; - passes << PassPair(srLightOmniPass, Light::Omni) << PassPair(srLightSpotPass, Light::Cone); - QColor back = view->fogColor_; - back.setAlpha(0); - foreach (PassPair pass, passes) { - if (bindShader(pass.first, &prog)) { - fbo_out.setWriteBuffer(first_wr_buff + pass.second); - glClearFramebuffer(back, false); - if (clear_only) continue; - setUniformCamera(prog, cam); - setUniformViewCorners(prog, cam); - prog->setUniformValue("lights_start", lights_start[pass.second]); - prog->setUniformValue("lights_count", cur_lights[pass.second].size()); - prog->setUniformValue("fog_color", view->fogColor_); - prog->setUniformValue("fog_decay", qMax(view->fogDecay_, 0.001f)); - prog->setUniformValue("fog_density", view->fogDensity_); - prog->setUniformValue("view_mat", cam->viewMatrix().inverted().toGenericMatrix<3,3>()); - renderQuad(prog, quad, cam); - } - } -} - - -void Renderer::renderScene() { - initShaders(); - tex_env.load(); - QOpenGLExtraFunctions * f = view; - Scene & scene(*(view->scene_)); - Camera * cam = view->camera(); - QOpenGLShaderProgram * prog = 0; - bool scene_changed = scene.prepare(); - scene.destroyUnused(f); - - /// reload materials on change - if (scene_changed || scene.need_reload_materials) { - //if (scene.need_reload_materials) - // maps_hash = 0; - rend_selection.generateObjectsID(scene); - reloadMaterials(scene); - if (edit_mode) - recreateMaterialThumbnails(); - emit view->materialsChanged(); - } - - /// material thumbnails - if (edit_mode && !scene_changed) { - rend_mat.procQueue(); - } - - /// lights - cur_lights = scene.lights_used; - bool use_camlight = (camera_light_mode == QGLView::clmOn); - if ((camera_light_mode == QGLView::clmAuto) && cur_lights.isEmpty()) - use_camlight = true; - if (use_camlight) { - cur_lights[Light::Omni] << cam_light; - cam_light->setPos(cam->pos()); - } - if (scene.lights_changed) { - scene.lights_changed = false; - reloadLightsParameters(cur_lights); - } - reloadLightsPositions(cam); - - /// selection - if (edit_mode) { - rend_selection.renderSelection(scene); - } - - /// solid geometry pass - fbo_ds.bind(); - glEnableDepth(); - glClearFramebuffer(); - if (bindShader(srGeometryPass, &prog)) { - setUniformCamera(prog, cam); - textures_empty.bind(f, tarEmpty); - textures_maps .bind(f, tarMaps ); - renderObjects(scene, rpSolid); - } - fbo_ds.release(); - - /// lighting passes - renderLight(obrSolidOmni, scene.geometries_used[rpSolid].isEmpty()); - - /// transparent geometry pass - fbo_ds.bind(); - glEnableDepth(); - glClearFramebuffer(Qt::black, false); - if (bindShader(srGeometryPass, &prog)) { - renderObjects(scene, rpTransparent); - } - fbo_ds.release(); - - /// lighting passes - renderLight(obrTransparentOmni, scene.geometries_used[rpTransparent].isEmpty()); - - /// blending layers - if (bindShader(srFinalPass, &prog)) { - //fbo_ds .bindColorTexture(dbrNormalZ , 0); - fbo_out.bindColorTexture(obrSolidOmni , 1); - fbo_out.bindColorTexture(obrSolidSpot , 2); - fbo_out.bindColorTexture(obrTransparentOmni, 3); - fbo_out.bindColorTexture(obrTransparentSpot, 4); - fbo_out.setWriteBuffer(obrSum); - renderQuad(prog, quad); - } - - /// tonemapping - if (tone_proc.process()) - fbo_out.bind(); - if (bindShader(srTonemapPass, &prog)) { - prog->setUniformValue("gamma", gamma_); - prog->setUniformValue("frame_max", tone_proc.frameMax()); - fbo_out.bindColorTexture(obrSum, 0); - fbo_out.setWriteBuffer(obrTonemap); - renderQuad(prog, quad); - } else - fbo_out.blit(obrSum, fbo_out.id(), obrTonemap, fbo_out.rect(), fbo_out.rect()); - fbo_out.release(); - - /// apply hovers and selection frame - if (edit_mode) { - rend_selection.drawSelection(fbo_out, obrTonemap); - rend_service.renderService(); - } else { - fbo_out.blit(obrTonemap, 0, 0, fbo_out.rect(), QRect(QPoint(), view->size())); - } - //fbo_small_16.blit(0, 0, 0, fbo_small_16.rect(), fbo_small_16.rect(), GL_COLOR_BUFFER_BIT, GL_LINEAR); - -} - - -void Renderer::setCameraLightMode(int m) { - camera_light_mode = m; - view->scene()->setLightsChanged(); -} diff --git a/qglengine/renderer.h b/qglengine/renderer.h deleted file mode 100644 index d865bbb..0000000 --- a/qglengine/renderer.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - QGL Renderer - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef RENDERER_H -#define RENDERER_H - -#include "renderer_base.h" -#include "renderer_material.h" -#include "renderer_service.h" -#include "renderer_selection.h" -#include "tonemapping_proc.h" -#include "glcubemap.h" -#include - - -class Renderer: public RendererBase { - friend class QGLView; - friend class MouseController; - friend class RendererBase; - friend class RendererMaterial; - friend class RendererService; - friend class RendererSelection; - friend class TonemappingProc; - enum ShaderRole { - // Selection - srSelectionFill, - srSelectionHalo, - srSelectionApply, - srSelectionFrame, - - // Service - srServiceFill, - srServiceFrame, - srServiceLine, - - // Deferred shading - srGeometryPass, - srLightOmniPass, - srLightSpotPass, - srFinalPass, - srTonemapPass, - }; - enum DeferredBufferRole { - dbrDiffuse, - dbrNormalZ, - dbrSpecularReflect, - dbrEmissionRough, - dbrSpeedBitangXY, - - dbrBuffersCount, - }; - enum OutBufferRole { - obrTonemap, - obrSum, - obrSolidOmni, - obrSolidSpot, - obrTransparentOmni, - obrTransparentSpot, - - obrBuffersCount, - }; - -public: - Renderer(QGLView * view_); - virtual ~Renderer(); - - void init(int width, int height); - void resize(int width, int height); - void reloadShaders(); - void renderScene(); - void setCameraLightMode(int m); - int cameraLightMode() const {return camera_light_mode;} - - QImage materialThumbnail(Material * m) {return rend_mat.materialThumbnail(m);} - void recreateMaterialThumbnails(bool force_all = false) {rend_mat.recreateMaterialThumbnails(force_all);} - -protected: - void fillObjectsBuffer(const ObjectBaseList & ol, RenderPass pass); - void reloadObjects(); - void renderObjects(Scene & scene, RenderPass pass); - void renderLight(int first_wr_buff, bool clear_only); - - bool bindShader(ShaderRole role, QOpenGLShaderProgram ** ret = 0); - bool bindShader(QOpenGLShaderProgram * sp); - void initShaders(); - void releaseShader(); - -private: - float gamma_; - int camera_light_mode; - bool edit_mode, need_init_shaders, need_render_sum; - Framebuffer fbo_ds, fbo_out; - /*QOpenGLShaderProgram * shader_fxaa, * shader_ds_0, * shader_ds_1, * shader_hdr, * shader_small; - QOpenGLShaderProgram * shader_bloom_0, * shader_bloom_1, * shader_motion_blur, * shader_fbo_add; - QOpenGLShaderProgram * shader_shadow, * shader_ssr, * shader_ssr_blur, * shader_ssr_merge; - QOpenGLShaderProgram * shader_ssao_blur, * shader_ssao_merge, * shader_dof;*/ - QMap shader_files; - QMap shader_defines; - QMap shaders; - QOpenGLShaderProgram * shader_fxaa; - - RendererMaterial rend_mat; - RendererService rend_service; - RendererSelection rend_selection; - TonemappingProc tone_proc; - - Mesh * quad; - Light * cam_light; - CubeTexture tex_env; - - QPoint mouse_pos; - QRect mouse_rect; - QMatrix4x4 prev_view, prev_proj; - QMatrix3x3 nm; - QVector4D corner_dirs[4]; - QVector hcontent; - QMap> cur_lights; - -}; - -#endif // RENDERER_H diff --git a/qglengine/renderer_base.cpp b/qglengine/renderer_base.cpp deleted file mode 100644 index f22c287..0000000 --- a/qglengine/renderer_base.cpp +++ /dev/null @@ -1,442 +0,0 @@ -/* - QGL RendererBase - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#define GL_GLEXT_PROTOTYPES -#include -#include "renderer_base.h" -#include "renderer.h" -#include "qglview.h" -#include "glmesh.h" -#include "gltexture_manager.h" -#include "glshaders_headers.h" - -using namespace QGLEngineShaders; - - -RendererBase::RendererBase(QGLView * view_): - view(view_), - buffer_materials (GL_UNIFORM_BUFFER, GL_STREAM_DRAW), - buffer_lights (GL_UNIFORM_BUFFER, GL_STREAM_DRAW), - buffer_lights_pos(GL_UNIFORM_BUFFER, GL_STREAM_DRAW), - textures_empty(false), - textures_maps(true) -{ - textures_manager = new TextureManager(view); - maps_size = QSize(512, 512); - maps_hash = 0; - tex_coeff[0] = tex_coeff[1] = 0; - -} - - -RendererBase::~RendererBase() { - delete textures_manager; -} - - -void RendererBase::initTextureArrays() { - QOpenGLExtraFunctions * f = view; - textures_maps.init(f); - textures_empty.init(f); - textures_empty.resize(f, QSize(1, 1), 2); - textures_empty.bind(f); - QImage im(1, 1, QImage::Format_RGBA8888); - im.fill(0xFFFFFFFF); - textures_empty.load(f, im, emrWhite); - im.fill(0xFF8080); - textures_empty.load(f, im, emrBlue); -} - - -void RendererBase::initUniformBuffer(QOpenGLShaderProgram * prog, Buffer * buffer, int bind_point, const char * blockName) { - if (!prog || !buffer) return; - if (!prog->isLinked()) return; - QOpenGLExtraFunctions * f = view; - buffer->init(f); - //glClearError(); - GLint ubo_ind = f->glGetUniformBlockIndex(prog->programId(), blockName); - f->glUniformBlockBinding(prog->programId(), ubo_ind, bind_point); - f->glBindBufferBase(GL_UNIFORM_BUFFER, bind_point, buffer->ID()); - //qDebug() << "initUBO" << QString::number(f->glGetError(), 16); -} - - -void RendererBase::setUniformHalo(QOpenGLShaderProgram * prog, const char * type, QColor color, float fill) { - prog->setUniformValue((QString(type) + "_color").toLatin1().constData(), color); - prog->setUniformValue((QString(type) + "_fill" ).toLatin1().constData(), fill); -} - - -void RendererBase::setUniformMaps(QOpenGLShaderProgram * prog) { - prog->setUniformValue("qgl_texture_array[0]", (int)tarEmpty); - prog->setUniformValue("qgl_texture_array[1]", (int)tarMaps ); -} - - -void RendererBase::setUniformCamera(QOpenGLShaderProgram * prog, Camera * cam, bool matrices, QSize viewport) { - double w = view->width(), h = view->height(); - if (viewport.isValid()) { - w = viewport.width(); - h = viewport.height(); - } - QMatrix4x4 mat_view, mat_proj; - if (cam) { - if (matrices) { - mat_view = cam->fullViewMatrix(); - mat_proj = cam->projectionMatrix(w / h); - } - prog->setUniformValue("z_near", cam->depthStart()); - } - prog->setUniformValue("dt", QVector2D(1. / w, 1. / h)); - prog->setUniformValue("qgl_ViewMatrix" , mat_view); - prog->setUniformValue("qgl_ViewProjMatrix", mat_proj * mat_view); -} - - -void RendererBase::setUniformViewCorners(QOpenGLShaderProgram * prog, Camera * cam, QSize viewport) { - double w = view->width(), h = view->height(); - if (viewport.isValid()) { - w = viewport.width(); - h = viewport.height(); - } - QMatrix4x4 mproji = cam->projectionMatrix(w / h).inverted(); - QMatrix4x4 mviewi = cam->viewMatrix().inverted(); - QVector4D corner_dirs[4], world_dirs[4]; - corner_dirs[0] = (mproji * QVector4D(-1, -1, 0, 1)); - corner_dirs[1] = (mproji * QVector4D(-1, 1, 0, 1)); - corner_dirs[2] = (mproji * QVector4D( 1, 1, 0, 1)); - corner_dirs[3] = (mproji * QVector4D( 1, -1, 0, 1)); - for (int i = 0; i < 4; ++i) { - world_dirs[i] = mviewi.mapVector(corner_dirs[i].toVector3D()); - prog->setUniformValue(QString("view_corners[%1]").arg(i).toLatin1().constData(), corner_dirs[i]); - prog->setUniformValue(QString("world_corners[%1]").arg(i).toLatin1().constData(), world_dirs[i]); - } -} - - -void RendererBase::fillSelectionsBuffer(QVector & buffer, const ObjectBaseList & ol) { - buffer.resize(ol.size()); - for (int i = 0; i < ol.size(); ++i) { - buffer[i] = (ol[i]->isSelected(true) ? 1 : 0); - } -} - - -void RendererBase::fillSelectionsBuffer(QVector & buffer, bool yes, int size) { - buffer.resize(size); - for (int i = 0; i < size; ++i) - buffer[i] = (yes ? 1 : 0); -} - - -void RendererBase::reloadMaterials(Scene & scene) { - //qDebug() << "reloadMaterias"; - QList maps[2]; - QMap tex_layers[2]; - foreach (Material * m, scene.materials) { - if (m->map_diffuse .hasBitmap()) maps[0] << &(m->map_diffuse ); - if (m->map_normal .hasBitmap()) maps[1] << &(m->map_normal ); - if (m->map_metalness.hasBitmap()) maps[0] << &(m->map_metalness); - if (m->map_roughness.hasBitmap()) maps[0] << &(m->map_roughness); - if (m->map_emission .hasBitmap()) maps[0] << &(m->map_emission ); - if (m->map_relief .hasBitmap()) maps[0] << &(m->map_relief ); - } - for (int i = 0; i < 2; ++i) { - foreach (Map * m, maps[i]) - tex_layers[i][m->bitmap_path] = 0; - } - int layers_count = tex_layers[0].size() + tex_layers[1].size(), cl = -1; - uint cur_maps_hash = qHash(tex_layers[0].keys()) ^ (qHash(tex_layers[1].keys()) + 0xF00FF00F); - if (maps_hash != cur_maps_hash) { - maps_hash = cur_maps_hash; - textures_maps.resize(view, maps_size, layers_count); - textures_maps.bind(view); - for (int i = 0; i < 2; ++i) { - QMutableMapIterator it(tex_layers[i]); - while (it.hasNext()) { - it.next(); - QImage im = textures_manager->loadTextureImage(it.key(), i == 1); - textures_maps.load(view, im, ++cl); - it.value() = cl; - } - foreach (Map * m, maps[i]) { - m->_layer = tex_layers[i].value(m->bitmap_path); - //qDebug() << "assign" << m->bitmap_path << "layer" << m->_layer; - } - } - textures_maps.mipmaps(view); -// qDebug() << "load" << (cl+1) << "bitmaps"; - } - - QGLMaterial glm; - cur_materials_.clear(); - cur_materials_ << glm; - foreach (Material * m, scene.materials) { - if (cur_materials_.size() >= max_materials) { - qDebug() << "[QGLEngine] Warning: Too many materials! Maximum" << max_materials; - break; - } - //m->load(textures_manager); - m->_index = cur_materials_.size(); - m->_changed = false; - glm.color_diffuse = QColor2QVector(m->color_diffuse ); - glm.color_emission = QColor2QVector(m->color_emission); - glm.transparency = m->transparency; - glm.reflectivity = m->reflectivity; - glm.iof = m->iof ; - glm.dispersion = m->dispersion ; - m->map_diffuse .copyToQGLMap(glm.map[mtDiffuse ]); - m->map_normal .copyToQGLMap(glm.map[mtNormal ]); - m->map_metalness.copyToQGLMap(glm.map[mtMetalness ]); - m->map_roughness.copyToQGLMap(glm.map[mtRoughness]); - m->map_emission .copyToQGLMap(glm.map[mtEmission ]); - m->map_relief .copyToQGLMap(glm.map[mtRelief ]); - cur_materials_ << glm; - } - //qDebug() << "load" << cur_materials_.size() << "materials"; - //textures_maps.resize(maps_size, ); - //cur_materials_[0].color_diffuse = QColor2QVector(Qt::red); - buffer_materials.bind(view); - buffer_materials.resize(view, cur_materials_.size() * sizeof(QGLMaterial)); - buffer_materials.load(view, cur_materials_.constData(), cur_materials_.size() * sizeof(QGLMaterial)); - scene.need_reload_materials = false; - -} - - -void RendererBase::reloadLightsParameters(const QMap> & lights) { - lights_start.clear(); - lights_start[Light::Omni] = 0; - QMapIterator> it(lights); - current_lights.clear(); - while (it.hasNext()) { - it.next(); - lights_start[it.key()] = current_lights.size(); - current_lights.append(it.value()); - } - cur_lights_params_.resize(qMin(current_lights.size(), max_lights)); - //qDebug() << "reloadLightsParameters" << cur_lights_params_.size(); - for (int i = 0; i < cur_lights_params_.size(); ++i) { - QGLLightParameter & so(cur_lights_params_[i]); - Light * l = current_lights[i]; - double ang_start = l->angle_start / 2.f, ang_end = l->angle_end / 2.f; - if (l->light_type == Light::Omni) - ang_start = ang_end = 180.; - //qDebug() << "light" << light->name() << ulightn << pos; - so.color = QColor2QVector(l->color_); - so.angles[0] = ang_start; - so.angles[1] = cos(ang_start * deg2rad); - so.angles[2] = ang_end; - so.angles[3] = cos(ang_end * deg2rad); - so.decay_intensity[0] = l->decay_const; - so.decay_intensity[1] = l->decay_linear; - so.decay_intensity[2] = l->decay_quadratic; - so.decay_intensity[3] = l->intensity; - //so.shadow = shadow; - //so.shadowColor = shadow; - } - buffer_lights.bind(view); - buffer_lights.resize(view, cur_lights_params_.size() * sizeof(QGLLightParameter)); - buffer_lights.load(view, cur_lights_params_.constData(), cur_lights_params_.size() * sizeof(QGLLightParameter)); -} - - -void RendererBase::reloadLightsPositions(Camera * cam) { - cur_lights_pos_.resize(qMin(current_lights.size(), max_lights)); - QMatrix4x4 mat = cam->viewMatrix() * cam->offsetMatrix(); - for (int i = 0; i < cur_lights_pos_.size(); ++i) { - QGLLightPosition & so(cur_lights_pos_[i]); - Light * l = current_lights[i]; - QMatrix4x4 m = mat * l->worldTransform(); - QVector4D pos(0, 0, 0, 1.), dir(QVector3D(0,0,-1), 1);//, dir0(light->dir0), dir1(light->dir1); - pos = m * pos; - dir = (m * QVector4D(QVector3D(0,0,-1),0)).normalized();//((m * dir) - pos).normalized(); - so.position = pos; - so.direction = dir; - //so.shadowMatrix = l->shadow_matrix; - } - buffer_lights_pos.bind(view); - buffer_lights_pos.resize(view, cur_lights_pos_.size() * sizeof(QGLLightPosition)); - buffer_lights_pos.load(view, cur_lights_pos_.constData(), cur_lights_pos_.size() * sizeof(QGLLightPosition)); -} - - -void RendererBase::markReloadTextures() { - maps_hash = 0; - textures_manager->clearImageCache(); - view->scene_->need_reload_materials = true; -} - - -void RendererBase::setMapsSize(QSize sz) { - maps_size = sz; - markReloadTextures(); -} - - -void RendererBase::initQuad(Mesh * mesh, QMatrix4x4 mat) { - QGLEngineShaders::Object quab_object; - mat.transposed().copyDataTo(quab_object.modelmatrix); - mesh->init(view); - mesh->loadObject(view, quab_object); -} - - -void RendererBase::renderQuad(QOpenGLShaderProgram * prog, Mesh * mesh, Camera * cam, bool uniforms) { - glDisableDepth(); - if (uniforms) - setUniformCamera(prog, cam, false); - mesh->draw(view, 1); -} - - - - -float RadicalInverse_VdC(uint bits) { - bits = (bits << 16u) | (bits >> 16u); - bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u); - bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u); - bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u); - bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u); - return float(bits) * 2.3283064365386963e-10; // / 0x100000000 -} -// ---------------------------------------------------------------------------- -QVector2D Hammersley(uint i, uint N) { - return QVector2D(float(i)/float(N), RadicalInverse_VdC(i)); -} -QVector3D ImportanceSampleGGX(QVector2D Xi, QVector3D N, float roughness) { - float a = roughness*roughness; - float phi = 2.0 * M_PI * Xi[0]; - float cosTheta = sqrt((1.0 - Xi[1]) / (1.0 + (a*a - 1.0) * Xi[1])); - float sinTheta = sqrt(1.0 - cosTheta*cosTheta); - // преобразование из сферических в декартовы координаты - QVector3D H; - H[0] = cos(phi) * sinTheta; - H[1] = sin(phi) * sinTheta; - H[2] = cosTheta; - // преобразование из касательного пространства в мировые координаты - QVector3D up = qAbs(N[2]) < 0.999 ? QVector3D(0.0, 0.0, 1.0) : QVector3D(1.0, 0.0, 0.0); - QVector3D tangent = QVector3D::crossProduct(up, N).normalized(); - QVector3D bitangent = QVector3D::crossProduct(N, tangent); - QVector3D sampleVec = tangent * H[0] + bitangent * H[1] + N * H[2]; - return sampleVec.normalized(); -} -float GeometrySchlickGGX(float NdotV, float roughness) { - float k = (roughness * roughness) / 2.0; - float nom = NdotV; - float denom = NdotV * (1.0 - k) + k; - return nom / denom; -} -float GeometrySmith(QVector3D N, QVector3D V, QVector3D L, float roughness) { - float NdotV = piMax(QVector3D::dotProduct(N, V), 0.f); - float NdotL = piMax(QVector3D::dotProduct(N, L), 0.f); - float ggx2 = GeometrySchlickGGX(NdotV, roughness); - float ggx1 = GeometrySchlickGGX(NdotL, roughness); - return ggx1 * ggx2; -} -QVector2D IntegrateBRDF(float NdotV, float roughness) { - QVector3D V; - V[0] = sqrt(1.f - NdotV*NdotV); - V[1] = 0.f; - V[2] = NdotV; - float A = 0.f; - float B = 0.f; - QVector3D N = QVector3D(0.f, 0.f, 1.f); - const uint SAMPLE_COUNT = 256u; - for(uint i = 0u; i < SAMPLE_COUNT; ++i) { - QVector2D Xi = Hammersley(i, SAMPLE_COUNT); - QVector3D H = ImportanceSampleGGX(Xi, N, roughness); - QVector3D L = (2.f * QVector3D::dotProduct(V, H) * H - V).normalized(); - float NdotL = piMax(L[2], 0.f); - float NdotH = piMax(H[2], 0.f); - float VdotH = piMax(QVector3D::dotProduct(V, H), 0.f); - if(NdotL > 0.f) { - float G = GeometrySmith(N, V, L, roughness); - float G_Vis = (G * VdotH) / (NdotH * NdotV); - float Fc = pow(1.f - VdotH, 5.f); - A += (1.f - Fc) * G_Vis; - B += Fc * G_Vis; - } - } - A /= float(SAMPLE_COUNT); - B /= float(SAMPLE_COUNT); - return QVector2D(A, B); -} - -void RendererBase::initCoeffTextures() { - QImage im = QImage(":/coeffs_brdf.png").mirrored(); - int size = im.width(); - QVector data(size*size); - int ind = -1; - for (int x = 0; x < size; ++x) { - //float c = x / double(size - 1) + 1.E-3; - for (int y = 0; y < size; ++y) { - //float r = y / double(size - 1); - QColor p = im.pixelColor(x, y); - data[++ind] = QVector2D(p.redF(), p.greenF());//IntegrateBRDF(c, 1.f - r + 1.E-3); - } - } - createCoeffTexture(tex_coeff[0], data.constData(), size, 2); - /*const int size = 512; - QVector data_diff(size*size), data_spec(size*size); - double r, c, c2; - int ind = -1; - for (int x = 0; x < size; ++x) { - c = x / double(size - 1); - c = sqrt(c); - c = piMax(1.E-16, c); - c2 = c*c; - for (int y = 0; y < size; ++y) { - r = y / double(size - 1); - double r_d = r; - double r_s = r*r*r; - r_d = piMax(1.E-16, r_d); - r_s = piMax(1.E-16, r_s); - - double ndlc = (1. - c2) / c2; - double diff = 2. / (1. + sqrt(1. + (1. - r_d) * ndlc)); - - double spec = c2 * (r_s + ndlc); - spec = r_s / (spec * spec) / M_PI; - - ++ind; - data_diff[ind] = piClamp(diff, 1.E-12, 1.E+36); - data_spec[ind] = piClamp(spec, 1.E-12, 1.E+36); - } - } - createCoeffTexture(tex_coeff[0], data_diff, size); - createCoeffTexture(tex_coeff[1], data_spec, size);*/ -} - - -void RendererBase::createCoeffTexture(GLuint & id, const void * data, int size, int channels) { - QOpenGLExtraFunctions * f = view; - deleteGLTexture(f, id); - f->glGenTextures(1, &id); - f->glBindTexture(GL_TEXTURE_2D, id); - f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); - f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - GLenum iformat = GL_R16F, format = GL_RED; - if (channels == 2) {iformat = GL_RG16F; format = GL_RG;} - if (channels == 3) {iformat = GL_RGB16F; format = GL_RGB;} - if (channels == 4) {iformat = GL_RGBA16F; format = GL_RGBA;} - f->glTexImage2D(GL_TEXTURE_2D, 0, iformat, size, size, 0, format, GL_FLOAT, data); -} diff --git a/qglengine/renderer_base.h b/qglengine/renderer_base.h deleted file mode 100644 index e0f5574..0000000 --- a/qglengine/renderer_base.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - QGL RendererBase - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef RENDERER_BASE_H -#define RENDERER_BASE_H - -#include "glshaders_types.h" -#include "gltexturearray.h" -#include "glbuffer.h" - - -class RendererBase { -public: - RendererBase(QGLView * view_); - ~RendererBase(); - -protected: - void initTextureArrays(); - void initUniformBuffer (QOpenGLShaderProgram * prog, Buffer * buffer, int bind_point, const char * blockName); - void setUniformHalo (QOpenGLShaderProgram * prog, const char * type, QColor color, float fill); - void setUniformMaps (QOpenGLShaderProgram * prog); - void setUniformCamera (QOpenGLShaderProgram * prog, Camera * cam, bool matrices = true, QSize viewport = QSize()); - void setUniformViewCorners(QOpenGLShaderProgram * prog, Camera * cam, QSize viewport = QSize()); - void fillSelectionsBuffer(QVector & buffer, const ObjectBaseList & ol); - void fillSelectionsBuffer(QVector & buffer, bool yes, int size); - void reloadMaterials(Scene & scene); - void reloadLightsParameters(const QMap> & lights); - void reloadLightsPositions (Camera * cam); - void markReloadTextures(); - void setMapsSize(QSize sz); - void initQuad(Mesh * mesh, QMatrix4x4 mat = QMatrix4x4()); - void renderQuad(QOpenGLShaderProgram * prog, Mesh * mesh, Camera * cam = 0, bool uniforms = true); - void initCoeffTextures(); - void createCoeffTexture(GLuint & id, const void * data, int size, int channels = 1); - - QGLView * view; - TextureManager * textures_manager; - QVector cur_objects_; - QVector cur_materials_; - QVector cur_lights_params_; - QVector cur_lights_pos_; - Buffer buffer_materials; - Buffer buffer_lights, buffer_lights_pos; - Texture2DArray textures_empty, textures_maps; - QSize maps_size; - uint maps_hash; - GLuint tex_coeff[2]; - QMap lights_start; - QList current_lights; - -}; - -#endif // RENDERER_BASE_H diff --git a/qglengine/renderer_material.cpp b/qglengine/renderer_material.cpp deleted file mode 100644 index 0e6c594..0000000 --- a/qglengine/renderer_material.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - QGL RendererMaterial - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#define GL_GLEXT_PROTOTYPES -#include -#include "renderer_material.h" -#include "renderer.h" -#include "qglview.h" -#include "glmesh.h" -#include "gltexture_manager.h" -#include - -using namespace QGLEngineShaders; - - -RendererMaterial::RendererMaterial(Renderer * r_): r(r_), - fbo_mat_thumb(r->view, 6, true , GL_RGBA16F) { - mat_sphere = Primitive::ellipsoid(16, 16); - mat_camera = new Camera(); - mat_camera->setPos(QVector3D(2, 2, 2)); - mat_camera->setAim(QVector3D()); - mat_camera->setFOV(45.); - mat_light = new Light(); - mat_light->setPos(QVector3D(50, 100, 25)); - last_thumb_material = 0; -} - - -RendererMaterial::~RendererMaterial() { - delete mat_sphere; - delete mat_camera; - delete mat_light; -} - - -void RendererMaterial::init(int width, int height) { - resize(width, height); -} - - -void RendererMaterial::resize(int width, int height) { - fbo_mat_thumb.enablePixelBuffer(); - fbo_mat_thumb.resize(256, 256); -} - - -void RendererMaterial::renderMaterial(Material * m) { - //qDebug() << "renderMaterial" << m; - last_thumb_material = m; - QOpenGLShaderProgram * prog = 0; - QOpenGLExtraFunctions * f = r->view; - fbo_mat_thumb.bind(); - glEnableDepth(); - glClearFramebuffer(QColor(0,0,0,0)); - if (r->bindShader(Renderer::srGeometryPass, &prog)) { - r->setUniformMaps(prog); - r->setUniformCamera(prog, mat_camera, true, fbo_mat_thumb.size()); - //qDebug() << mat_camera->viewMatrix(); - r->textures_empty.bind(f, tarEmpty); - r->textures_maps .bind(f, tarMaps ); - Object o; - o.material = m->_index; - mat_sphere->loadObject(f, o); - mat_sphere->draw(f, 1); - } - fbo_mat_thumb.bindColorTextures(); - fbo_mat_thumb.bindDepthTexture(5); - fbo_mat_thumb.setWriteBuffer(5); - if (r->bindShader(Renderer::srLightOmniPass, &prog)) { - r->setUniformCamera(prog, mat_camera, true, fbo_mat_thumb.size()); - r->setUniformViewCorners(prog, mat_camera, fbo_mat_thumb.size()); - for (int i = 0; i < 5; ++i) - prog->setUniformValue(QString("tex_%1").arg(i).toLatin1().constData(), i); - prog->setUniformValue("tex_d", 5); - prog->setUniformValue("lights_start", 0); - prog->setUniformValue("lights_count", 1); - QMap> mat_l; - mat_l[Light::Omni] << mat_light; - r->reloadLightsParameters(mat_l); - r->reloadLightsPositions(mat_camera); - glClearFramebuffer(r->view->backColor(), false); - r->renderQuad(prog, r->quad, mat_camera); - r->view->scene()->setLightsChanged(); - } - fbo_mat_thumb.queryImage(5); - fbo_mat_thumb.release(); -} - - -void RendererMaterial::procQueue() { - if (last_thumb_material) { - mat_thumbnails[last_thumb_material] = fbo_mat_thumb.getImage(); - emit r->view->materialThumbnailCreated(last_thumb_material); - last_thumb_material = 0; - } - if (!mat_thumb_queue.isEmpty()) - renderMaterial(mat_thumb_queue.dequeue()); -} - - -QImage RendererMaterial::materialThumbnail(Material * m) { - return mat_thumbnails.value(m); -} - - -void RendererMaterial::recreateMaterialThumbnails(bool force_all) { - if (force_all) { - mat_thumb_queue.clear(); - //qDebug() << "recreateMaterialThumbnails" << view->scene_->materials; - foreach (Material * m, r->view->scene_->materials) - mat_thumb_queue.enqueue(m); - } else { - foreach (Material * m, r->view->scene_->changed_materials) - if (!mat_thumb_queue.contains(m)) - mat_thumb_queue.enqueue(m); - } -} diff --git a/qglengine/renderer_material.h b/qglengine/renderer_material.h deleted file mode 100644 index 3c08a7b..0000000 --- a/qglengine/renderer_material.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - QGL RendererMaterial - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef RENDERER_MATERIAL_H -#define RENDERER_MATERIAL_H - -#include "glframebuffer.h" -#include - - -class RendererMaterial { - friend class QGLView; - -public: - RendererMaterial(Renderer * r_); - virtual ~RendererMaterial(); - - void init(int width, int height); - void resize(int width, int height); - - QImage materialThumbnail(Material * m); - void recreateMaterialThumbnails(bool force_all = false); - void renderMaterial(Material * m); - void procQueue(); - -private: - Renderer * r; - - Framebuffer fbo_mat_thumb; - Mesh * mat_sphere; - Camera * mat_camera; - Light * mat_light; - QMap mat_thumbnails; - Material * last_thumb_material; - QQueue mat_thumb_queue; - -}; - -#endif // RENDERER_MATERIAL_H diff --git a/qglengine/renderer_selection.cpp b/qglengine/renderer_selection.cpp deleted file mode 100644 index 00897a7..0000000 --- a/qglengine/renderer_selection.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/* - QGL RendererSelection - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#define GL_GLEXT_PROTOTYPES -#include -#include "renderer_selection.h" -#include "qglview.h" -#include "glmesh.h" -#include - -using namespace QGLEngineShaders; - - -RendererSelection::RendererSelection(Renderer * r_): r(r_), - fbo_selection(r->view, 6) { - sel_frame = Primitive::plane(2., 2.); - id_hover = 0; - line_thick_ = 2.; - scale_ = 0.5; -} - - -RendererSelection::~RendererSelection() { - delete sel_frame; -} - - -void RendererSelection::init(int width, int height) { - resize(width, height); -} - - -void RendererSelection::resize(int width, int height) { - line_thick_ = lineThickness() + 1.; - scale_ = 0.5 / appScale(); - fbo_selection.enablePixelBuffer(); - fbo_selection.resize(width * scale_, height * scale_); - //fbo_selection.setColorTextureFiltering(sbrSrcHover , GL_LINEAR); - //fbo_selection.setColorTextureFiltering(sbrSrcSelect, GL_LINEAR); -} - - -void RendererSelection::generateObjectsID(Scene & scene) { - ids.clear(); - aim_ids.clear(); - QList passes = scene.geometries_used.keys(); - foreach (int p, passes) { - QMapIterator it(scene.geometries_used[p]); - while (it.hasNext()) { - it.next(); - foreach (ObjectBase * o, it.value()) { - uint id = qHash(o); - ids[id] = o; - o->id_ = id; - } - } - QMapIterator> lit(scene.lights_used); - while (lit.hasNext()) { - lit.next(); - foreach (ObjectBase * o, lit.value()) { - uint id = qHash(o); - ids[id] = o; - aim_ids[id + 1] = o; - o->id_ = id; - } - } - foreach (Camera * o, scene.cameras_used) { - uint id = qHash(o); - ids[id] = o; - aim_ids[id + 1] = o; - o->id_ = id; - } - } -} - - -void RendererSelection::renderSelection(Scene & scene) { - QOpenGLShaderProgram * prog = 0; - QGLView * view = r->view; - MouseController & mc(view->mouse); - if (r->bindShader(Renderer::srSelectionFill, &prog)) { - mc.hov_objects.clear(); - mc.hov_aims.clear(); - id_hover = 0; - if (fbo_selection.queriedPoints() > 0) { - if (fbo_selection.queriedPoints() == 1) { - id_hover = fbo_selection.getPoint(); - ObjectBase * o = ids.value(id_hover); - if (o) - mc.hov_objects << o; - else { - o = aim_ids.value(id_hover); - if (o) - mc.hov_aims << o; - } - //qDebug() << id_hover; - } else { - QVector points = fbo_selection.getPointsByte(); - QSet ids_hover; - foreach (uint i, points) - ids_hover << i; - foreach (uint i, ids_hover) { - ObjectBase * o = ids.value(i); - if (o) mc.hov_objects << o; - o = aim_ids.value(i); - if (o) mc.hov_aims << o; - } - //qDebug() << ids_hover; - } - } - - fbo_selection.bind(); - - fbo_selection.setWriteBuffers(); - glEnableDepth(); - glClearFramebuffer(QColor(0,0,0,0)); - r->setUniformCamera(prog, view->camera()); - r->renderObjects(scene, rpSolid); - r->renderObjects(scene, rpTransparent); - view->glClear(GL_DEPTH_BUFFER_BIT); - - RendererService & rs(r->rend_service); - rs.drawLights(); - rs.drawCameras(); - rs.drawCurrentHandleObjects(); - - //mouse_rect = fbo_selection.rect(); - if (r->mouse_rect.isNull()) - fbo_selection.queryPoint(0, r->mouse_pos * scale_); - else - fbo_selection.queryPoints(0, QRect(r->mouse_rect.topLeft() * scale_, - r->mouse_rect.size() * scale_)); - - //qDebug() << id_hover; - fbo_selection.bindColorTexture(sbrSrcHover , sbrSrcHover ); - fbo_selection.bindColorTexture(sbrSrcSelect, sbrSrcSelect); - fbo_selection.setWriteBuffers(QVector() << sbrHovered << sbrSelected); - if (!view->hoverHalo_ && !view->selectionHalo_) - glClearFramebuffer(QColor(0,0,0,0), false); - else { - r->bindShader(Renderer::srSelectionHalo, &prog); - r->setUniformHalo(prog, "hover" , view->hoverHaloColor() , view->hoverHaloFillAlpha()); - r->setUniformHalo(prog, "selection", view->selectionHaloColor(), view->selectionHaloFillAlpha()); - prog->setUniformValue("has_hover" , view->hoverHalo_ && (id_hover > 0) ? 1.f : 0.f); - prog->setUniformValue("has_selection", view->selectionHalo_ ? 1.f : 0.f); - prog->setUniformValue("fb_hover" , (int)sbrSrcHover); - prog->setUniformValue("fb_selection", (int)sbrSrcSelect); - prog->setUniformValue("hover_id", QVector4D(float( id_hover & 0xFF) / 255.f, - float((id_hover >> 8 ) & 0xFF) / 255.f, - float((id_hover >> 16) & 0xFF) / 255.f, - float((id_hover >> 24) & 0xFF) / 255.f)); - r->renderQuad(prog, r->quad, view->camera()); - } - - prog = r->shader_fxaa; - if (r->bindShader(prog)) { - r->setUniformCamera(prog, 0, true, fbo_selection.size()); - fbo_selection.bindColorTexture(sbrHovered); - fbo_selection.setWriteBuffer(sbrHoveredFXAA); - r->renderQuad(prog, r->quad, 0, false); - fbo_selection.bindColorTexture(sbrSelected); - fbo_selection.setWriteBuffer(sbrSelectedFXAA); - r->renderQuad(prog, r->quad, 0, false); - } - - fbo_selection.release(); - } -} - - -void RendererSelection::renderSelectionFrame() { - QOpenGLShaderProgram * prog = 0; - if (r->bindShader(Renderer::srSelectionFrame, &prog)) { - QMatrix4x4 mat; - double mrx = r->mouse_rect.x(), mrw = r->mouse_rect.width() , vw = r->view->width(); - double mry = r->mouse_rect.y(), mrh = r->mouse_rect.height(), vh = r->view->height(); - mat.translate(-1. + (mrw + mrx*2) / vw, 1. - (mrh + mry*2) / vh, 0.); - mat.scale(mrw / vw, mrh / vh, 0.); - r->initQuad(sel_frame, mat); - prog->setUniformValue("size", QVector2D(mrw / vw, mrh / vh)); - prog->setUniformValue("thickness", line_thick_); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - r->renderQuad(prog, sel_frame); - glDisable(GL_BLEND); - } -} - - -void RendererSelection::drawSelection(Framebuffer & fbo_out, int index_out) { - QOpenGLShaderProgram * prog = 0; - if (r->bindShader(Renderer::srSelectionApply, &prog)) { - fbo_selection.bindColorTextures(); - fbo_out.bindColorTexture(index_out); - prog->setUniformValue("fb_out" , 0); - prog->setUniformValue("fb_hover" , (int)sbrHoveredFXAA ); - prog->setUniformValue("fb_select", (int)sbrSelectedFXAA); - r->renderQuad(prog, r->quad, r->view->camera()); - if (!r->mouse_rect.isNull()) { - renderSelectionFrame(); - } - } -} diff --git a/qglengine/renderer_selection.h b/qglengine/renderer_selection.h deleted file mode 100644 index 9062a18..0000000 --- a/qglengine/renderer_selection.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - QGL RendererSelection - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef RENDERER_SELECTION_H -#define RENDERER_SELECTION_H - -#include "renderer_service.h" -#include - - -class RendererSelection { - friend class QGLView; - friend class MouseController; - friend class Renderer; - friend class RendererService; - -public: - RendererSelection(Renderer * r_); - virtual ~RendererSelection(); - - void init(int width, int height); - void resize(int width, int height); - -protected: - enum SelectionBufferRole { - sbrSrcHover, - sbrSrcSelect, - sbrHovered, - sbrSelected, - sbrHoveredFXAA, - sbrSelectedFXAA, - }; - - void generateObjectsID(Scene & scene); - void renderSelection(Scene & scene); - void renderSelectionFrame(); - void drawSelection(Framebuffer & fbo_out, int index_out = 0); - -private: - Renderer * r; - - Framebuffer fbo_selection; - Mesh * sel_frame; - float line_thick_, scale_; - - QVector cur_selections_; - QHash ids; - QHash aim_ids; - uint id_hover; - -}; - -#endif // RENDERER_selection_H diff --git a/qglengine/renderer_service.cpp b/qglengine/renderer_service.cpp deleted file mode 100644 index e71a183..0000000 --- a/qglengine/renderer_service.cpp +++ /dev/null @@ -1,490 +0,0 @@ -/* - QGL RendererService - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#define GL_GLEXT_PROTOTYPES -#include -#include "renderer_service.h" -#include "renderer.h" -#include "qglview.h" -#include "glmesh.h" -#include - -using namespace QGLEngineShaders; - - -RendererService::RendererService(Renderer * r_): r(r_) { - line_width = 1; - current_action = haNoAction; - current_handle = 0; - mat_xyz.resize(3); mat_ms2.resize(3); - color_xyz.resize(3); color_ms2.resize(3); - const QVector3D _rot [3] = {QVector3D(0,1,0), QVector3D(-1,0,0), QVector3D(0, 0,1)}; - const QVector3D _rot2[3] = {QVector3D(0,0,0), QVector3D( 1,0,0), QVector3D(0,-1,0)}; - for (int i = 0; i < 3; ++i) { - QMatrix4x4 m; - m.rotate(90., _rot[i]); - mat_xyz[i] = m; - m.setToIdentity(); - if (!_rot2[i].isNull()) - m.rotate(90., _rot2[i]); - mat_ms2[i] = m; - color_xyz[i] = color_ms2[i] = QVector4D(0,0,0,0.8); - color_xyz[i][i] = 1.; - } - color_ms2[0] = (color_xyz[0] + color_xyz[1]) / 2.; - color_ms2[1] = (color_xyz[0] + color_xyz[2]) / 2.; - color_ms2[2] = (color_xyz[1] + color_xyz[2]) / 2.; - axis_camera = new Camera(); - axis_camera->setAim(QVector3D()); - axis_camera->setFOV(45.); - axis_mesh = Primitive::arrow(12); - size_vp_scale = size_full_scale = 1.; - - box_mesh = Primitive::cube(0.8, 0.8, 0.8); - box_mesh_f = Primitive::cubeFrame(0.8, 0.8, 0.8); - omni_mesh = Primitive::ellipsoid(2, 1, 0.5); - omni_mesh_f = Primitive::ellipsoidFrame(2, 1, 0.5); - omni_mesh ->scalePoints(1.5); - omni_mesh_f ->scalePoints(1.5); - cone_mesh = Primitive::cone(8, 0.5, 1.); - cone_mesh_f = Primitive::coneFrame(8, 0.5, 1.); - QMatrix4x4 mat; - mat.translate(0,0,-1); - cone_mesh ->transformPoints(mat); - cone_mesh_f->transformPoints(mat); - cone_mesh_f->scalePoints(1.5); - - box_mesh ->scalePoints(1.3); - omni_mesh ->scalePoints(1.3); - cone_mesh ->translatePoints(0,0,0.5); - cone_mesh ->scalePoints(1.4); - cone_mesh ->translatePoints(0,0,-0.5); - cone_mesh ->scalePoints(1.5); - - camera_mesh = Primitive::cube(1.2, 1.2, 1.2); - mat.translate(0,0,-0.5); - Mesh * m = Primitive::cone(6, 0.6, 1.); - m->scalePoints(1.4); - m->transformPoints(mat); - camera_mesh->append(m); - camera_mesh_f = Primitive::cubeFrame(1., 1., 1.); - camera_mesh_f->append(Primitive::cubeFrame(0.5, 0.5, 0.5)); - m = Primitive::coneFrame(6, 0.6, 1.); - m->transformPoints(mat); - camera_mesh_f->append(m); - - line_spot_f = Primitive::lineFrame(QVector3D(), QVector3D(0, 0, -1)); - line_camera_f = Primitive::lineFrame(QVector3D(), QVector3D(0, 0, -1)); - - handle_move_mesh = Primitive::arrow(12, 0.06); - handle_ms_2_mesh = Primitive::torus(8, 12, 0.5, 0.02, 90); - m = Primitive::disc(8, 0.5, 90); - handle_ms_2_mesh->append(m); - m->flipNormals(); - handle_ms_2_mesh->append(m); - delete m; - - handle_rotate_mesh = Primitive::arrow(12, 0.03); - m = Primitive::torus(30, 12, 0.5, 0.06); - m->translatePoints(QVector3D(0., 0., 0.75)); - handle_rotate_mesh->append(m); - delete m; - - handle_scale_mesh = Primitive::cylinder(12, 0.03, 0.85); - m = Primitive::ellipsoid(12, 12, 0.15); - m->translatePoints(QVector3D(0., 0., 0.85)); - handle_scale_mesh->append(m); - delete m; - handle_scale_3_mesh = Primitive::ellipsoid(12, 12, 0.2); - - handle_move_mesh ->scalePoints(7.5); - handle_ms_2_mesh ->scalePoints(7.5); - handle_rotate_mesh ->scalePoints(7.5); - handle_scale_mesh ->scalePoints(7.5); - handle_scale_3_mesh->scalePoints(7.5); -} - - -RendererService::~RendererService() { - delete box_mesh; - delete box_mesh_f; - delete omni_mesh; - delete omni_mesh_f; - delete cone_mesh; - delete cone_mesh_f; - delete camera_mesh; - delete camera_mesh_f; - delete line_spot_f; - delete line_camera_f; - delete axis_camera; - delete axis_mesh; - delete handle_move_mesh; - delete handle_ms_2_mesh; - delete handle_rotate_mesh; - delete handle_scale_mesh; - delete handle_scale_3_mesh; -} - - -void RendererService::init(int width, int height) { - fillXYZObjects(); - axis_mesh->loadObjects(r->view, cur_objects); - resize(width, height); -} - - -void RendererService::resize(int width, int height) { - axis_viewport = preferredIconSize(10.); - line_width = lineThickness(); - size_vp_scale = 25. * appScale() / qMax(qMin(width, height), 1); - //qDebug() << axis_viewport; -} - - -QMatrix4x4 RendererService::invariantSizeMatrix(QVector3D p, double * ret_scale) { - QVector4D pos = QVector4D(p, 1.); - double dist = -(v_mat * pos).z(); - QMatrix4x4 m; - m.translate(pos.toVector3D()); - m.scale(dist * size_full_scale); - if (ret_scale) *ret_scale = dist * size_full_scale; - return m; -} - - -QMatrix4x4 RendererService::parentRotationMatrix(ObjectBase * o, bool self_rotation) { - QMatrix4x4 ret; - if (!o) return ret; - QMatrix4x4 pmat; - if (o->parent()) { - pmat = o->parent()->transform().matrixRotate(); - } - if (self_rotation) { - ret *= o->transform().matrixRotate(); - } - ret = pmat * ret; - return ret; -} - - -void RendererService::fillXYZObjects() { - cur_objects.resize(3); - for (int i = 0; i < 3; ++i) { - cur_objects[i].color = color_xyz[i]; - mat_xyz[i].transposed().copyDataTo(cur_objects[i].modelmatrix); - } -} - - -void RendererService::fillOmniObjects() { - QList ll = r->view->scene()->lights_used.value(Light::Omni); - Object o; - cur_objects.clear(); - foreach (Light * l, ll) { - QMatrix4x4 m = invariantSizeMatrix(l->worldPos()); - m.transposed().copyDataTo(o.modelmatrix); - o.object_id = l->id_; - cur_objects << o; - } -} - - -void RendererService::fillAimedObjects(const ObjectBaseList & objects, Mesh * line_mesh) { - Object o; - cur_objects.clear(); - cur_aims.clear(); - QVector & lv (line_mesh->vertices ()); - QVector & ln (line_mesh->normals ()); - QVector & lt (line_mesh->texcoords ()); - QVector< Vector2i> & lind(line_mesh->indicesLines()); - lv.clear(); - foreach (ObjectBase * go, objects) { - AimedObject * ao = (AimedObject *)go; - QMatrix4x4 m; - m = invariantSizeMatrix(ao->worldPos()) * parentRotationMatrix(ao); - m.transposed().copyDataTo(o.modelmatrix); - o.object_id = ao->id_; - cur_objects << o; - - lv << ao->worldPos() << ao->worldAim(); - - m = invariantSizeMatrix(ao->worldAim()); - m.transposed().copyDataTo(o.modelmatrix); - o.object_id = ao->id_ + 1; - cur_aims << o; - } - ln.resize(lv.size()); - lt.resize(lv.size()); - lind.resize(lv.size() / 2); - for (int i = 0; i < lind.size(); ++i) { - lind[i] = Vector2i(i*2, i*2 + 1); - } -} - - -void RendererService::fillHandleObjects(QVector3D center, HandleMesh ids[], const QVector & mats, const QVector & colors, QMatrix4x4 add_mat, int count) { - QMatrix4x4 m = invariantSizeMatrix(center) * add_mat; - cur_objects.resize(count); - for (int i = 0; i < count; ++i) { - cur_objects[i].color = colors[i]; - QMatrix4x4 omat = m * mats[i]; - cur_objects[i].object_id = ids[i]; - if (current_handle.testFlag(ids[i])) { - cur_objects[i].color = QVector4D(0,1,1,1); - } - omat.transposed().copyDataTo(cur_objects[i].modelmatrix); - } -} - - -bool RendererService::calculateCenter() { - ObjectBaseList sol = r->view->scene()->selectedObjects(true); - if (sol.isEmpty()) return false; - selection_center = sol[0]->worldPos(); - if (sol.size() > 1) { - Box3D bb; - foreach (ObjectBase * o, sol) { - o->calculateBoundingBox(); - bb |= o->boundingBox(); - } - if (!bb.isEmpty()) { - selection_center = bb.center(); - } - } - axis_mat = QMatrix4x4(); - if ((sol.size() == 1)) { - if (current_action == haMove) { - if (sol[0]->selected_aim) - selection_center = ((AimedObject*)sol[0])->worldAim(); - } else { - axis_mat = parentRotationMatrix(sol[0]); - } - } - return true; -} - - -void RendererService::drawCurrentHandleObjects() { - if (current_action == haNoAction) return; - if (calculateCenter()) { - HandleMesh ids[3]; - switch (current_action) { - case haMove : ids[0] = hmMoveX ; ids[1] = hmMoveY ; ids[2] = hmMoveZ ; break; - case haRotate: ids[0] = hmRotateX; ids[1] = hmRotateY; ids[2] = hmRotateZ; break; - case haScale : ids[0] = hmScaleX ; ids[1] = hmScaleY ; ids[2] = hmScaleZ ; break; - default: break; - } - fillHandleObjects(selection_center, ids, mat_xyz, color_xyz, axis_mat); - Mesh * hm = currentHandleMesh(); - QVector sel; - sel.fill(0, 3); - if (hm) { - hm->loadObjects(r->view, cur_objects); - hm->loadSelections(r->view, sel); - hm->draw(r->view, 3); - } - if (current_action == haMove || current_action == haScale) { - switch (current_action) { - case haMove : ids[0] = hmMoveXY ; ids[1] = hmMoveXZ ; ids[2] = hmMoveYZ ; break; - case haScale : ids[0] = hmScaleXY ; ids[1] = hmScaleXZ ; ids[2] = hmScaleYZ ; break; - default: break; - } - hm = handle_ms_2_mesh; - fillHandleObjects(selection_center, ids, mat_ms2, color_ms2, axis_mat); - hm->loadObjects(r->view, cur_objects); - hm->loadSelections(r->view, sel); - hm->draw(r->view, 3); - if (current_action == haScale) { - hm = handle_scale_3_mesh; - QVector mv; mv.resize(1); - QVector cv; cv.fill(QVector4D(1, 1, 0.5, 1), 1); - ids[0] = hmMaxScale; - fillHandleObjects(selection_center, ids, mv, cv, axis_mat, 1); - hm->loadObjects(r->view, cur_objects); - hm->loadSelections(r->view, sel); - hm->draw(r->view, 1); - } - } - } -} - - -void RendererService::drawLights() { - QGLView * v = r->view; - RendererSelection & rs(r->rend_selection); - - fillOmniObjects(); - omni_mesh->loadObjects(v, cur_objects); - r->fillSelectionsBuffer(rs.cur_selections_, lights2objectList(v->scene_->lights_used.value(Light::Omni))); - omni_mesh->loadSelections(v, rs.cur_selections_); - omni_mesh->draw(v, cur_objects.size()); - - ObjectBaseList ll = lights2objectList(r->view->scene()->lights_used.value(Light::Cone)); - fillAimedObjects(ll, line_spot_f); - cone_mesh->loadObjects(v, cur_objects); - r->fillSelectionsBuffer(rs.cur_selections_, ll); - cone_mesh->loadSelections(v, rs.cur_selections_); - cone_mesh->draw(v, cur_objects.size()); - box_mesh->loadObjects(v, cur_aims); - box_mesh->loadSelections(v, rs.cur_selections_); - box_mesh->draw(v, cur_aims.size()); - -} - - -void RendererService::drawLightsFrame(QColor color) { - QGLView * v = r->view; - RendererSelection & rs(r->rend_selection); - - fillOmniObjects(); - setObjectsColor(cur_objects, color); - omni_mesh_f->loadObjects(v, cur_objects); - r->fillSelectionsBuffer(rs.cur_selections_, lights2objectList(v->scene_->lights_used.value(Light::Omni))); - omni_mesh_f->loadSelections(v, rs.cur_selections_); - omni_mesh_f->draw(v, cur_objects.size()); - - ObjectBaseList ll = lights2objectList(r->view->scene()->lights_used.value(Light::Cone)); - fillAimedObjects(ll, line_spot_f); - setObjectsColor(cur_objects, color); - cone_mesh_f->loadObjects(v, cur_objects); - r->fillSelectionsBuffer(rs.cur_selections_, ll); - cone_mesh_f->loadSelections(v, rs.cur_selections_); - cone_mesh_f->draw(v, cur_objects.size()); - - setObjectsColor(cur_aims, color); - box_mesh_f->loadObjects(v, cur_aims); - box_mesh_f->loadSelections(v, rs.cur_selections_); - box_mesh_f->draw(v, cur_aims.size()); - -} - - -void RendererService::drawCameras() { - QGLView * v = r->view; - RendererSelection & rs(r->rend_selection); - - ObjectBaseList cl = cameras2objectList(r->view->scene()->cameras_used); - cl.removeOne(r->view->camera()); - fillAimedObjects(cl, line_camera_f); - camera_mesh->loadObjects(v, cur_objects); - r->fillSelectionsBuffer(rs.cur_selections_, cl); - camera_mesh->loadSelections(v, rs.cur_selections_); - camera_mesh->draw(v, cur_objects.size()); - box_mesh->loadObjects(v, cur_aims); - box_mesh->loadSelections(v, rs.cur_selections_); - box_mesh->draw(v, cur_aims.size()); - -} - - -void RendererService::drawCamerasFrame(QColor color) { - QGLView * v = r->view; - RendererSelection & rs(r->rend_selection); - - ObjectBaseList cl = cameras2objectList(r->view->scene()->cameras_used); - cl.removeOne(r->view->camera()); - fillAimedObjects(cl, line_camera_f); - setObjectsColor(cur_objects, color); - camera_mesh_f->loadObjects(v, cur_objects); - r->fillSelectionsBuffer(rs.cur_selections_, cl); - camera_mesh_f->loadSelections(v, rs.cur_selections_); - camera_mesh_f->draw(v, cur_objects.size()); - - setObjectsColor(cur_aims, color); - box_mesh_f->loadObjects(v, cur_aims); - box_mesh_f->loadSelections(v, rs.cur_selections_); - box_mesh_f->draw(v, cur_aims.size()); - -} - - -void RendererService::setObjectsColor(QVector & ol, QColor col) { - QVector4D cv = QColor2QVector(col); - for (int i = 0; i < ol.size(); ++i) - ol[i].color = cv; -} - - -void RendererService::renderService() { - QOpenGLShaderProgram * prog = 0; - QOpenGLExtraFunctions * f = r->view; - size_full_scale = tan(r->view->camera()->FOV() / 2. * deg2rad) * size_vp_scale; - v_mat = r->view->camera()->fullViewMatrix(); - f->glEnable(GL_MULTISAMPLE); - glEnableDepth(); - f->glClear(GL_DEPTH_BUFFER_BIT); - glDisable(GL_CULL_FACE); - if (r->bindShader(Renderer::srServiceFrame, &prog)) { - prog->setUniformValue("qgl_ProjMatrix", r->view->camera()->projectionMatrix(r->view->aspect)); - - /// lights - r->setUniformCamera(prog, r->view->camera()); - - prog->setUniformValue("line_width", 2.f); - prog->setUniformValue("z_offset", 0.f); - drawLightsFrame(Qt::white); - drawCamerasFrame(Qt::white); - prog->setUniformValue("line_width", 1.f); - prog->setUniformValue("z_offset", -1.E-2f); - drawLightsFrame(Qt::black); - drawCamerasFrame(Qt::black); - - } - if (r->bindShader(Renderer::srServiceLine, &prog)) { - //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - r->setUniformCamera(prog, r->view->camera()); - line_object.color = QColor2QVector(Qt::white); - line_spot_f ->loadObject(f, line_object); - line_camera_f->loadObject(f, line_object); - line_spot_f ->draw(f, 1); - line_camera_f->draw(f, 1); - //glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - } - glEnable(GL_CULL_FACE); - if (r->bindShader(Renderer::srServiceFill, &prog)) { - r->setUniformCamera(prog, r->view->camera()); - - /// handles - f->glEnable(GL_BLEND); - f->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - drawCurrentHandleObjects(); - f->glDisable(GL_BLEND); - - /// axis - f->glViewport(0, 0, axis_viewport.width(), axis_viewport.height()); - axis_camera->setPos(-r->view->camera()->direction() * 3.); - axis_camera->setAim(QVector3D()); - axis_camera->setRotation(r->view->camera()->rotation()); - r->setUniformCamera(prog, axis_camera, true, axis_viewport); - axis_mesh->draw(f, 3); - f->glViewport(0, 0, r->view->width(), r->view->height()); - - } - f->glDisable(GL_MULTISAMPLE); -} - - -Mesh * RendererService::currentHandleMesh() { - switch (current_action) { - case haMove : return handle_move_mesh; - case haRotate: return handle_rotate_mesh; - case haScale : return handle_scale_mesh; - default: break; - } - return 0; -} diff --git a/qglengine/renderer_service.h b/qglengine/renderer_service.h deleted file mode 100644 index c0de71f..0000000 --- a/qglengine/renderer_service.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - QGL RendererService - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef RENDERER_SERVICE_H -#define RENDERER_SERVICE_H - -#include "glframebuffer.h" -#include "glshaders_types.h" -#include - - -class RendererService { - friend class QGLView; - friend class MouseController; - friend class Renderer; - friend class RendererSelection; - -public: - RendererService(Renderer * r_); - virtual ~RendererService(); - - enum HandleAction { - haNoAction, - haMove, - haRotate, - haScale, - }; - - enum HandleMesh { - hmMoveX = 0x01, - hmMoveY = 0x02, - hmMoveZ = 0x04, - hmMoveXY = hmMoveX | hmMoveY, - hmMoveXZ = hmMoveX | hmMoveZ, - hmMoveYZ = hmMoveY | hmMoveZ, - hmMaxMove = hmMoveX | hmMoveY | hmMoveZ, - hmRotateX = 0x08, - hmRotateY = 0x10, - hmRotateZ = 0x20, - hmMaxRotate = hmRotateX | hmRotateY | hmRotateZ, - hmScaleX = 0x40, - hmScaleY = 0x80, - hmScaleZ = 0x100, - hmScaleXY = hmScaleX | hmScaleY, - hmScaleXZ = hmScaleX | hmScaleZ, - hmScaleYZ = hmScaleY | hmScaleZ, - hmMaxScale = hmScaleX | hmScaleY | hmScaleZ, - }; - - void init(int width, int height); - void resize(int width, int height); - - QMatrix4x4 invariantSizeMatrix(QVector3D p, double * ret_scale = 0); - QMatrix4x4 parentRotationMatrix(ObjectBase * o, bool self_rotation = true); - void fillXYZObjects(); - void fillOmniObjects(); - void fillAimedObjects(const ObjectBaseList & objects, Mesh * line_mesh); - void fillHandleObjects(QVector3D center, HandleMesh ids[], const QVector & mats, const QVector & colors, QMatrix4x4 add_mat, int count = 3); - bool calculateCenter(); - void drawCurrentHandleObjects(); - void drawLights(); - void drawLightsFrame(QColor color); - void drawCameras(); - void drawCamerasFrame(QColor color); - void setObjectsColor(QVector & ol, QColor col); - void renderService(); - void setCurrentAction(HandleAction ha) {current_action = ha;} - Mesh * currentHandleMesh(); - -private: - Renderer * r; - - Mesh * axis_mesh, * handle_move_mesh, * handle_rotate_mesh, * handle_scale_mesh; - Mesh * handle_ms_2_mesh, * handle_scale_3_mesh; - Mesh * box_mesh_f, * omni_mesh_f, * cone_mesh_f, * camera_mesh_f; - Mesh * box_mesh, * omni_mesh, * cone_mesh, * camera_mesh; - Mesh * line_spot_f, * line_camera_f; - QMatrix4x4 v_mat, axis_mat; - QVector3D selection_center; - QVector mat_xyz, mat_ms2; - QVector color_xyz, color_ms2; - QVector cur_objects, cur_aims; - QGLEngineShaders::Object line_object; - Camera * axis_camera; - QSize axis_viewport; - HandleAction current_action; - QFlags current_handle; - int line_width; - double size_vp_scale, size_full_scale; - -}; - -#endif // RENDERER_SERVICE_H diff --git a/qglengine/shaders.qrc b/qglengine/shaders.qrc deleted file mode 100644 index ad92bf9..0000000 --- a/qglengine/shaders.qrc +++ /dev/null @@ -1,19 +0,0 @@ - - - shaders/ds_final.glsl - shaders/ds_geom.glsl - shaders/ds_light.glsl - shaders/ds_tonemap.glsl - shaders/fxaa.frag - shaders/fxaa.vert - shaders/fxaa_v3.h - shaders/selection.glsl - shaders/selection_apply.glsl - shaders/selection_frame.glsl - shaders/selection_halo.glsl - shaders/service_fill.glsl - shaders/service_frame.glsl - shaders/service_line.glsl - shaders/sum.glsl - - diff --git a/qglengine/shaders/ds_final.glsl b/qglengine/shaders/ds_final.glsl deleted file mode 100644 index 73aecb6..0000000 --- a/qglengine/shaders/ds_final.glsl +++ /dev/null @@ -1,22 +0,0 @@ -// vert // - -void main(void) { - gl_Position = qgl_ftransform(); -} - - -// frag // - -uniform sampler2D tex_g1, tex_s_0, tex_s_1, tex_t_0, tex_t_1; - -void main(void) { - ivec2 tc = ivec2(gl_FragCoord.xy); - vec4 vs0 = texelFetch(tex_s_0, tc, 0); - vec4 vs1 = texelFetch(tex_s_1, tc, 0); - vec3 sr = vs0.rgb + vs1.rgb; - vec4 vt0 = texelFetch(tex_t_0, tc, 0); - vec4 vt1 = texelFetch(tex_t_1, tc, 0); - vec3 tr = vt0.rgb + vt1.rgb; - float alpha = (vt0.a + vt1.a) / 2; - qgl_FragColor.rgb = mix(sr, tr, alpha); -} diff --git a/qglengine/shaders/ds_geom.glsl b/qglengine/shaders/ds_geom.glsl deleted file mode 100644 index 617a6ee..0000000 --- a/qglengine/shaders/ds_geom.glsl +++ /dev/null @@ -1,71 +0,0 @@ -// vert // - -out vec3 geom_normal; -out mat3 TBN; -out vec4 object_color; - -void main(void) { - qgl_MaterialIndex = qgl_Material; - qgl_FragTexture = qgl_Texture; - gl_Position = qgl_ftransform(); - - geom_normal = normalize(qgl_Normal * qgl_getNormalMatrix()); - TBN = qgl_getTangentMatrix() * mat3(qgl_Tangent, qgl_Bitangent, qgl_Normal); - object_color = qgl_ObjectColor; -} - - -// frag // - -in vec3 geom_normal; -in mat3 TBN; -in vec4 object_color; - -uniform vec2 dt; -uniform float z_near; - -const vec3 luma = vec3(0.299, 0.587, 0.114); -const float _pe = 2.4e-7; - -void main(void) { - vec2 tc = qgl_FragTexture.xy; - - vec4 diffuse = qgl_materialTexture(QGL_MAP_DIFFUSE, tc, vec4(0)) * object_color; - diffuse.rgb *= qgl_material[qgl_MaterialIndex].color_diffuse.rgb; - diffuse.a *= (1.f - qgl_material[qgl_MaterialIndex].transparency); - - vec3 normal, dn; - dn = qgl_materialTexture(QGL_MAP_NORMAL, tc, -vec4(0.5, 0.5, 1., 0.)).xyz; - //dn.y = -dn.y; - float dn_sl = length(dn); - dn = TBN * dn; - dn *= dn_sl / (length(dn) + 1E-6); - normal = normalize(geom_normal + dn); - - float metalness = dot(qgl_materialTexture(QGL_MAP_METALNESS, tc, vec4(0)).rgb, luma); - metalness = clamp(metalness, 0, 1); - - float roughness = dot(qgl_materialTexture(QGL_MAP_ROUGHNESS, tc, vec4(0)).rgb, luma); - roughness = clamp(roughness, 0.0001, 0.9999); - - float reflectivity = clamp(qgl_material[qgl_MaterialIndex].reflectivity, 0., 1.); - - vec4 emission = qgl_materialTexture(QGL_MAP_EMISSION, tc, vec4(0)); - emission *= qgl_material[qgl_MaterialIndex].color_emission; - - float height = dot(qgl_materialTexture(QGL_MAP_RELIEF, tc, vec4(0)).rgb, luma); - - float z = gl_FragCoord.z; - z = z + z - 1; - z = ((_pe - 2.) * z_near) / (z + _pe - 1.); // infinite depth - - qgl_FragData[0] = vec4(diffuse .rgba); - qgl_FragData[1] = vec4(normal .xyz, z); - qgl_FragData[2] = vec4(metalness, roughness, reflectivity, 0); - qgl_FragData[3] = vec4(emission.rgb, 0/*bn.x*/); - //qgl_FragData[4] = vec4(speed.xy, bn.yz); - - //ivec2 itc = ivec2(gl_FragCoord.xy); - //qgl_FragData[0].rgb = vec3(dot(n,vec3(0,0,1))); - //qgl_FragData[0].rgb = diffuse.rgb * dot(n,vec3(0,0,1)); -} diff --git a/qglengine/shaders/ds_light.glsl b/qglengine/shaders/ds_light.glsl deleted file mode 100644 index 7f8c132..0000000 --- a/qglengine/shaders/ds_light.glsl +++ /dev/null @@ -1,181 +0,0 @@ -// vert // - -out vec3 view_dir, world_dir; - -uniform vec4 view_corners[4], world_corners[4]; - -void main(void) { - qgl_FragTexture = qgl_Texture; - gl_Position = qgl_ftransform(); - view_dir = view_corners [gl_VertexID].xyz; - world_dir = world_corners[gl_VertexID].xyz; -} - - -// frag // - -in vec3 view_dir, world_dir; - -uniform vec2 dt; -uniform float z_near; -uniform sampler2D tex_coeffs[2]; -uniform sampler2D tex_0, tex_1, tex_2, tex_3, tex_4; -uniform samplerCube tex_env; -uniform int lights_start, lights_count; - -uniform vec4 fog_color = vec4(0.5, 0.5, 0.5, 1); -uniform float fog_decay = 10, fog_density = 0; -uniform mat3 view_mat; - -const vec3 luma = vec3(0.299, 0.587, 0.114); -const float _min_rough = 1.e-8, max_lod = 8; - -vec4 pos, lpos, shp; -vec3 li, si, ldir, halfV, bn, bn2, lwdir; -//vec3 vds, vds2; -float rough_diff, rough_spec, dist, NdotL, NdotH, spot, ldist, diff, spec, sdist, shadow; - -void calcLight(in int index, in vec3 n, in vec3 v) { - lpos = qgl_light_position[index].position; - ldir = lpos.xyz - (pos.xyz * lpos.w); - ldist = length(ldir); - ldir = normalize(ldir); - //ldir = vec3(0,0,1); - halfV = normalize(ldir + v); - NdotL = max(dot(n, ldir), 1E-8); - NdotH = max(dot(n, halfV), 1E-8); - spot = step(1.001E-8, NdotL) * qgl_light_parameter[index].decay_intensity.w; -#ifdef SPOT - float scos = max(dot(-ldir, qgl_light_position[index].direction.xyz), 0.); - spot *= scos * step(qgl_light_parameter[index].angles.w, scos); - spot *= smoothstep(qgl_light_parameter[index].angles.w, qgl_light_parameter[index].angles.y, scos); - /*//lwdir = mat3(mat_viewi) * qgl_Light[index].direction.xyz; - //bn = normalize(cross(lwdir, vec3(1, 0, 0))); - //bn2 = normalize(cross(lwdir, bn)); - float ds = ldist/200.;//max(abs(sdist) / 5000, 0.02); - //spot *= clamp(1. - sdist, 0, 1); - vds = ds * bn.xyz; - vds2 = ds * bn2.xyz; - float shadow = getShadow(index, pos.xyz, vec3(0)) * 3.; - shadow += getShadow(index, pos.xyz, vds ) * 2.; - shadow += getShadow(index, pos.xyz, - vds ) * 2.; - shadow += getShadow(index, pos.xyz, - vds2 ) * 2.; - shadow += getShadow(index, pos.xyz, + vds2 ) * 2.; - //shadow += getShadow(index, pos.xyz, vds - vds2 ) * 1.5; - //shadow += getShadow(index, pos.xyz, vds + vds2 ) * 1.5; - //shadow += getShadow(index, pos.xyz, - vds - vds2 ) * 1.5; - //shadow += getShadow(index, pos.xyz, - vds + vds2 ) * 1.5; - //shadow += getShadow(index, pos.xyz, vds + vds ); - //shadow += getShadow(index, pos.xyz, - vds - vds ); - //shadow += getShadow(index, pos.xyz, - vds2 - vds2); - //shadow += getShadow(index, pos.xyz, + vds2 + vds2); - //shadow += getShadow(index, pos.xyz, vds + vds - vds2 ); - //shadow += getShadow(index, pos.xyz, - vds - vds - vds2 ); - //shadow += getShadow(index, pos.xyz, vds + vds + vds2 ); - //shadow += getShadow(index, pos.xyz, - vds - vds + vds2 ); - //shadow += getShadow(index, pos.xyz, vds - vds2 - vds2); - //shadow += getShadow(index, pos.xyz, vds + vds2 + vds2); - //shadow += getShadow(index, pos.xyz, - vds - vds2 - vds2); - //shadow += getShadow(index, pos.xyz, - vds + vds2 + vds2); - //shadow += shadow += getShadow(index, pos.xyz, vds+vds2)*10; - spot *= mix(1., shadow / 11., shadow_on);*/ -#endif - vec3 dist_decay = vec3(1, ldist, ldist*ldist); - spot /= dot(qgl_light_parameter[index].decay_intensity.xyz, dist_decay); - - float NdotLs = NdotL*NdotL; - float NdotHs = NdotH*NdotH; - - float ndlc = (1. - NdotLs) / NdotLs; - diff = 2. / (1. + sqrt(1. + (1. - rough_diff) * ndlc)); - //diff = texture(tex_coeffs[0], vec2(roughness, (NdotLs))).r; - li += spot * diff * qgl_light_parameter[index].color.rgb; - - ndlc = (1. - NdotHs) / NdotHs; - float der = NdotHs * (rough_spec + ndlc); - spec = rough_spec / (der*der) / 3.1416; - //spec = texture(tex_coeffs[1], vec2(roughness, (NdotHs))).r; - si += spot * spec * qgl_light_parameter[index].color.rgb; -} - - - -float GeometrySchlickGGX(float NdotV, float roughness) { - float a = roughness; - float k = (a * a) / 2.0; - float nom = NdotV; - float denom = NdotV * (1.0 - k) + k; - return nom / denom; -} -// ---------------------------------------------------------------------------- -float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness) { - float NdotV = max(dot(N, V), 0.0); - float NdotL = max(dot(N, L), 0.0); - float ggx2 = GeometrySchlickGGX(NdotV, roughness); - float ggx1 = GeometrySchlickGGX(NdotL, roughness); - return ggx1 * ggx2; -} - - - -void main(void) { - ivec2 tc = ivec2(gl_FragCoord.xy); - vec4 v1 = texelFetch(tex_1, tc, 0); - float z = v1.w; - if (z == 1.) { - discard; - } - pos.w = 1; - pos.xyz = view_dir * z; - vec3 v = normalize(-pos.xyz); - - vec4 v0 = texelFetch(tex_0, tc, 0), - v2 = texelFetch(tex_2, tc, 0), - v3 = texelFetch(tex_3, tc, 0), - v4 = texelFetch(tex_4, tc, 0); - - vec3 diffuse = v0.rgb; - vec3 normal = v1.xyz; - vec3 emission = v3.rgb; - float alpha = v0.a; - float metalness = v2.r; - float roughness = v2.g; - float reflectivity = v2.b; - float NdotV = dot(normal, v); - float roughness3 = roughness*roughness*roughness; - //bn = normalize(vec3(v3.w, v4.zw)); - //bn2 = normalize(cross(n, bn)); - rough_diff = max(roughness, _min_rough); - rough_spec = max(roughness3, _min_rough); - float shlick = clamp(metalness + (1 - metalness) * pow(1 - NdotV, 5), 0, 1); - - li = vec3(0.);//qgl_AmbientLight.color.rgb * qgl_AmbientLight.intensity; - si = vec3(0.); - for (int i = 0; i < lights_count; ++i) - calcLight(lights_start + i, normal, v); - si *= shlick; - li *= (1 - shlick); - alpha = min(1, alpha * (1 + shlick)); - - vec2 brdf = texture(tex_coeffs[0], vec2(NdotV*0.99, roughness*0.995)).rg; - float env_spec = shlick * brdf.x + brdf.y; - vec3 spec_col = mix(vec3(1), diffuse, metalness); - vec3 env_dir = view_mat * reflect(-v, normal); - vec3 env_col = textureLod(tex_env, env_dir, sqrt(roughness) * max_lod).rgb * spec_col; - - vec3 res_col = max(vec3(0), li * diffuse + si * spec_col + emission); - res_col = mix(res_col, env_col, env_spec * reflectivity); - - float plen = length(pos.xyz); - float fog = 1 - exp(-plen / fog_decay); - fog = clamp(fog * fog_color.a * fog_density, 0, 1); - res_col = mix(res_col, fog_color.rgb, fog); - - qgl_FragColor = vec4(res_col, alpha); - - //vec3 specular = prefilteredColor * (F * envBRDF.x + envBRDF.y); - //qgl_FragColor.rgb = vec3(shlick * brdf.x + brdf.y); - //qgl_FragColor.rgb = vec3(alpha); - //qgl_FragColor.rgb = vec3(textureLod(tex_env, world_dir, 0).rgb); - //qgl_FragColor.a = 1.; -} diff --git a/qglengine/shaders/ds_tonemap.glsl b/qglengine/shaders/ds_tonemap.glsl deleted file mode 100644 index b9b1f8a..0000000 --- a/qglengine/shaders/ds_tonemap.glsl +++ /dev/null @@ -1,25 +0,0 @@ -// vert // - -void main(void) { - gl_Position = qgl_ftransform(); -} - - -// frag // - -uniform sampler2D tex_0; -uniform float gamma, frame_max; - -const vec3 luma = vec3(0.299, 0.587, 0.114); - -void main(void) { - ivec2 tc = ivec2(gl_FragCoord.xy); - vec4 src = texelFetch(tex_0, tc, 0); - vec3 res = src.rgb; - float l = dot(res, luma) * 0.75; - float g = gamma / frame_max; - res /= l; - l = 1 - exp(-l*g); - res *= l; - qgl_FragColor = vec4(res, dot(res, luma)); -} diff --git a/qglengine/shaders/fxaa.frag b/qglengine/shaders/fxaa.frag deleted file mode 100644 index 5e93037..0000000 --- a/qglengine/shaders/fxaa.frag +++ /dev/null @@ -1,2223 +0,0 @@ -/*============================================================================ - - - NVIDIA FXAA 3.11 by TIMOTHY LOTTES - - ------------------------------------------------------------------------------- -COPYRIGHT (C) 2010, 2011 NVIDIA CORPORATION. ALL RIGHTS RESERVED. ------------------------------------------------------------------------------- -TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED -*AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA -OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR -CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR -LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, -OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE -THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - ------------------------------------------------------------------------------- - INTEGRATION CHECKLIST ------------------------------------------------------------------------------- -(1.) -In the shader source, setup defines for the desired configuration. -When providing multiple shaders (for different presets), -simply setup the defines differently in multiple files. -Example, - - #define FXAA_PC 1 - #define FXAA_HLSL_5 1 - #define FXAA_QUALITY__PRESET 12 - -Or, - - #define FXAA_360 1 - -Or, - - #define FXAA_PS3 1 - -Etc. - -(2.) -Then include this file, - - #include "Fxaa3_11.h" - -(3.) -Then call the FXAA pixel shader from within your desired shader. -Look at the FXAA Quality FxaaPixelShader() for docs on inputs. -As for FXAA 3.11 all inputs for all shaders are the same -to enable easy porting between platforms. - - return FxaaPixelShader(...); - -(4.) -Insure pass prior to FXAA outputs RGBL (see next section). -Or use, - - #define FXAA_GREEN_AS_LUMA 1 - -(5.) -Setup engine to provide the following constants -which are used in the FxaaPixelShader() inputs, - - FxaaFloat2 fxaaQualityRcpFrame, - FxaaFloat4 fxaaConsoleRcpFrameOpt, - FxaaFloat4 fxaaConsoleRcpFrameOpt2, - FxaaFloat4 fxaaConsole360RcpFrameOpt2, - FxaaFloat fxaaQualitySubpix, - FxaaFloat fxaaQualityEdgeThreshold, - FxaaFloat fxaaQualityEdgeThresholdMin, - FxaaFloat fxaaConsoleEdgeSharpness, - FxaaFloat fxaaConsoleEdgeThreshold, - FxaaFloat fxaaConsoleEdgeThresholdMin, - FxaaFloat4 fxaaConsole360ConstDir - -Look at the FXAA Quality FxaaPixelShader() for docs on inputs. - -(6.) -Have FXAA vertex shader run as a full screen triangle, -and output "pos" and "fxaaConsolePosPos" -such that inputs in the pixel shader provide, - - // {xy} = center of pixel - FxaaFloat2 pos, - - // {xy__} = upper left of pixel - // {__zw} = lower right of pixel - FxaaFloat4 fxaaConsolePosPos, - -(7.) -Insure the texture sampler(s) used by FXAA are set to bilinear filtering. - - ------------------------------------------------------------------------------- - INTEGRATION - RGBL AND COLORSPACE ------------------------------------------------------------------------------- -FXAA3 requires RGBL as input unless the following is set, - - #define FXAA_GREEN_AS_LUMA 1 - -In which case the engine uses green in place of luma, -and requires RGB input is in a non-linear colorspace. - -RGB should be LDR (low dynamic range). -Specifically do FXAA after tonemapping. - -RGB data as returned by a texture fetch can be non-linear, -or linear when FXAA_GREEN_AS_LUMA is not set. -Note an "sRGB format" texture counts as linear, -because the result of a texture fetch is linear data. -Regular "RGBA8" textures in the sRGB colorspace are non-linear. - -If FXAA_GREEN_AS_LUMA is not set, -luma must be stored in the alpha channel prior to running FXAA. -This luma should be in a perceptual space (could be gamma 2.0). -Example pass before FXAA where output is gamma 2.0 encoded, - - color.rgb = ToneMap(color.rgb); // linear color output - color.rgb = sqrt(color.rgb); // gamma 2.0 color output - return color; - -To use FXAA, - - color.rgb = ToneMap(color.rgb); // linear color output - color.rgb = sqrt(color.rgb); // gamma 2.0 color output - color.a = dot(color.rgb, FxaaFloat3(0.299, 0.587, 0.114)); // compute luma - return color; - -Another example where output is linear encoded, -say for instance writing to an sRGB formated render target, -where the render target does the conversion back to sRGB after blending, - - color.rgb = ToneMap(color.rgb); // linear color output - return color; - -To use FXAA, - - color.rgb = ToneMap(color.rgb); // linear color output - color.a = sqrt(dot(color.rgb, FxaaFloat3(0.299, 0.587, 0.114))); // compute luma - return color; - -Getting luma correct is required for the algorithm to work correctly. - - ------------------------------------------------------------------------------- - BEING LINEARLY CORRECT? ------------------------------------------------------------------------------- -Applying FXAA to a framebuffer with linear RGB color will look worse. -This is very counter intuitive, but happends to be true in this case. -The reason is because dithering artifacts will be more visiable -in a linear colorspace. - - ------------------------------------------------------------------------------- - COMPLEX INTEGRATION ------------------------------------------------------------------------------- -Q. What if the engine is blending into RGB before wanting to run FXAA? - -A. In the last opaque pass prior to FXAA, - have the pass write out luma into alpha. - Then blend into RGB only. - FXAA should be able to run ok - assuming the blending pass did not any add aliasing. - This should be the common case for particles and common blending passes. - -A. Or use FXAA_GREEN_AS_LUMA. - -============================================================================*/ - -/*============================================================================ - - INTEGRATION KNOBS - -============================================================================*/ -// -// FXAA_PS3 and FXAA_360 choose the console algorithm (FXAA3 CONSOLE). -// FXAA_360_OPT is a prototype for the new optimized 360 version. -// -// 1 = Use API. -// 0 = Don't use API. -// -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_PS3 - #define FXAA_PS3 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_360 - #define FXAA_360 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_360_OPT - #define FXAA_360_OPT 0 -#endif -/*==========================================================================*/ -#ifndef FXAA_PC - // - // FXAA Quality - // The high quality PC algorithm. - // - #define FXAA_PC 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_PC_CONSOLE - // - // The console algorithm for PC is included - // for developers targeting really low spec machines. - // Likely better to just run FXAA_PC, and use a really low preset. - // - #define FXAA_PC_CONSOLE 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_GLSL_120 - #define FXAA_GLSL_120 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_GLSL_130 - #define FXAA_GLSL_130 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_HLSL_3 - #define FXAA_HLSL_3 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_HLSL_4 - #define FXAA_HLSL_4 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_HLSL_5 - #define FXAA_HLSL_5 0 -#endif -/*==========================================================================*/ -#ifndef FXAA_GREEN_AS_LUMA - // - // For those using non-linear color, - // and either not able to get luma in alpha, or not wanting to, - // this enables FXAA to run using green as a proxy for luma. - // So with this enabled, no need to pack luma in alpha. - // - // This will turn off AA on anything which lacks some amount of green. - // Pure red and blue or combination of only R and B, will get no AA. - // - // Might want to lower the settings for both, - // fxaaConsoleEdgeThresholdMin - // fxaaQualityEdgeThresholdMin - // In order to insure AA does not get turned off on colors - // which contain a minor amount of green. - // - // 1 = On. - // 0 = Off. - // - #define FXAA_GREEN_AS_LUMA 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_EARLY_EXIT - // - // Controls algorithm's early exit path. - // On PS3 turning this ON adds 2 cycles to the shader. - // On 360 turning this OFF adds 10ths of a millisecond to the shader. - // Turning this off on console will result in a more blurry image. - // So this defaults to on. - // - // 1 = On. - // 0 = Off. - // - #define FXAA_EARLY_EXIT 1 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_DISCARD - // - // Only valid for PC OpenGL currently. - // Probably will not work when FXAA_GREEN_AS_LUMA = 1. - // - // 1 = Use discard on pixels which don't need AA. - // For APIs which enable concurrent TEX+ROP from same surface. - // 0 = Return unchanged color on pixels which don't need AA. - // - #define FXAA_DISCARD 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_FAST_PIXEL_OFFSET - // - // Used for GLSL 120 only. - // - // 1 = GL API supports fast pixel offsets - // 0 = do not use fast pixel offsets - // - #ifdef GL_EXT_gpu_shader4 - #define FXAA_FAST_PIXEL_OFFSET 1 - #endif - #ifdef GL_NV_gpu_shader5 - #define FXAA_FAST_PIXEL_OFFSET 1 - #endif - #ifdef GL_ARB_gpu_shader5 - #define FXAA_FAST_PIXEL_OFFSET 1 - #endif - #ifndef FXAA_FAST_PIXEL_OFFSET - #define FXAA_FAST_PIXEL_OFFSET 0 - #endif -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_GATHER4_ALPHA - // - // 1 = API supports gather4 on alpha channel. - // 0 = API does not support gather4 on alpha channel. - // - #if (FXAA_HLSL_5 == 1) - #define FXAA_GATHER4_ALPHA 1 - #endif - #ifdef GL_ARB_gpu_shader5 - #define FXAA_GATHER4_ALPHA 1 - #endif - #ifdef GL_NV_gpu_shader5 - #define FXAA_GATHER4_ALPHA 1 - #endif - #ifndef FXAA_GATHER4_ALPHA - #define FXAA_GATHER4_ALPHA 0 - #endif -#endif - -/*============================================================================ - FXAA CONSOLE PS3 - TUNING KNOBS -============================================================================*/ -#ifndef FXAA_CONSOLE__PS3_EDGE_SHARPNESS - // - // Consoles the sharpness of edges on PS3 only. - // Non-PS3 tuning is done with shader input. - // - // Due to the PS3 being ALU bound, - // there are only two safe values here: 4 and 8. - // These options use the shaders ability to a free *|/ by 2|4|8. - // - // 8.0 is sharper - // 4.0 is softer - // 2.0 is really soft (good for vector graphics inputs) - // - #if 1 - #define FXAA_CONSOLE__PS3_EDGE_SHARPNESS 8.0 - #endif - #if 0 - #define FXAA_CONSOLE__PS3_EDGE_SHARPNESS 4.0 - #endif - #if 0 - #define FXAA_CONSOLE__PS3_EDGE_SHARPNESS 2.0 - #endif -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_CONSOLE__PS3_EDGE_THRESHOLD - // - // Only effects PS3. - // Non-PS3 tuning is done with shader input. - // - // The minimum amount of local contrast required to apply algorithm. - // The console setting has a different mapping than the quality setting. - // - // This only applies when FXAA_EARLY_EXIT is 1. - // - // Due to the PS3 being ALU bound, - // there are only two safe values here: 0.25 and 0.125. - // These options use the shaders ability to a free *|/ by 2|4|8. - // - // 0.125 leaves less aliasing, but is softer - // 0.25 leaves more aliasing, and is sharper - // - #if 1 - #define FXAA_CONSOLE__PS3_EDGE_THRESHOLD 0.125 - #else - #define FXAA_CONSOLE__PS3_EDGE_THRESHOLD 0.25 - #endif -#endif - -/*============================================================================ - FXAA QUALITY - TUNING KNOBS ------------------------------------------------------------------------------- -NOTE the other tuning knobs are now in the shader function inputs! -============================================================================*/ -#ifndef FXAA_QUALITY__PRESET - // - // Choose the quality preset. - // This needs to be compiled into the shader as it effects code. - // Best option to include multiple presets is to - // in each shader define the preset, then include this file. - // - // OPTIONS - // ----------------------------------------------------------------------- - // 10 to 15 - default medium dither (10=fastest, 15=highest quality) - // 20 to 29 - less dither, more expensive (20=fastest, 29=highest quality) - // 39 - no dither, very expensive - // - // NOTES - // ----------------------------------------------------------------------- - // 12 = slightly faster then FXAA 3.9 and higher edge quality (default) - // 13 = about same speed as FXAA 3.9 and better than 12 - // 23 = closest to FXAA 3.9 visually and performance wise - // _ = the lowest digit is directly related to performance - // _ = the highest digit is directly related to style - // - #define FXAA_QUALITY__PRESET 12 -#endif - - -/*============================================================================ - - FXAA QUALITY - PRESETS - -============================================================================*/ - -/*============================================================================ - FXAA QUALITY - MEDIUM DITHER PRESETS -============================================================================*/ -#if (FXAA_QUALITY__PRESET == 10) - #define FXAA_QUALITY__PS 3 - #define FXAA_QUALITY__P0 1.5 - #define FXAA_QUALITY__P1 3.0 - #define FXAA_QUALITY__P2 12.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 11) - #define FXAA_QUALITY__PS 4 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 3.0 - #define FXAA_QUALITY__P3 12.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 12) - #define FXAA_QUALITY__PS 5 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 4.0 - #define FXAA_QUALITY__P4 12.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 13) - #define FXAA_QUALITY__PS 6 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 4.0 - #define FXAA_QUALITY__P5 12.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 14) - #define FXAA_QUALITY__PS 7 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 4.0 - #define FXAA_QUALITY__P6 12.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 15) - #define FXAA_QUALITY__PS 8 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 2.0 - #define FXAA_QUALITY__P6 4.0 - #define FXAA_QUALITY__P7 12.0 -#endif - -/*============================================================================ - FXAA QUALITY - LOW DITHER PRESETS -============================================================================*/ -#if (FXAA_QUALITY__PRESET == 20) - #define FXAA_QUALITY__PS 3 - #define FXAA_QUALITY__P0 1.5 - #define FXAA_QUALITY__P1 2.0 - #define FXAA_QUALITY__P2 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 21) - #define FXAA_QUALITY__PS 4 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 22) - #define FXAA_QUALITY__PS 5 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 23) - #define FXAA_QUALITY__PS 6 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 24) - #define FXAA_QUALITY__PS 7 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 3.0 - #define FXAA_QUALITY__P6 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 25) - #define FXAA_QUALITY__PS 8 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 2.0 - #define FXAA_QUALITY__P6 4.0 - #define FXAA_QUALITY__P7 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 26) - #define FXAA_QUALITY__PS 9 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 2.0 - #define FXAA_QUALITY__P6 2.0 - #define FXAA_QUALITY__P7 4.0 - #define FXAA_QUALITY__P8 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 27) - #define FXAA_QUALITY__PS 10 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 2.0 - #define FXAA_QUALITY__P6 2.0 - #define FXAA_QUALITY__P7 2.0 - #define FXAA_QUALITY__P8 4.0 - #define FXAA_QUALITY__P9 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 28) - #define FXAA_QUALITY__PS 11 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 2.0 - #define FXAA_QUALITY__P6 2.0 - #define FXAA_QUALITY__P7 2.0 - #define FXAA_QUALITY__P8 2.0 - #define FXAA_QUALITY__P9 4.0 - #define FXAA_QUALITY__P10 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 29) - #define FXAA_QUALITY__PS 12 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 2.0 - #define FXAA_QUALITY__P6 2.0 - #define FXAA_QUALITY__P7 2.0 - #define FXAA_QUALITY__P8 2.0 - #define FXAA_QUALITY__P9 2.0 - #define FXAA_QUALITY__P10 4.0 - #define FXAA_QUALITY__P11 8.0 -#endif - -/*============================================================================ - FXAA QUALITY - EXTREME QUALITY -============================================================================*/ -#if (FXAA_QUALITY__PRESET == 39) - #define FXAA_QUALITY__PS 12 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.0 - #define FXAA_QUALITY__P2 1.0 - #define FXAA_QUALITY__P3 1.0 - #define FXAA_QUALITY__P4 1.0 - #define FXAA_QUALITY__P5 1.5 - #define FXAA_QUALITY__P6 2.0 - #define FXAA_QUALITY__P7 2.0 - #define FXAA_QUALITY__P8 2.0 - #define FXAA_QUALITY__P9 2.0 - #define FXAA_QUALITY__P10 4.0 - #define FXAA_QUALITY__P11 8.0 -#endif - - - -/*============================================================================ - - API PORTING - -============================================================================*/ -#if (FXAA_GLSL_120 == 1) || (FXAA_GLSL_130 == 1) - #define FxaaBool bool - #define FxaaDiscard discard - #define FxaaFloat float - #define FxaaFloat2 vec2 - #define FxaaFloat3 vec3 - #define FxaaFloat4 vec4 - #define FxaaHalf float - #define FxaaHalf2 vec2 - #define FxaaHalf3 vec3 - #define FxaaHalf4 vec4 - #define FxaaInt2 ivec2 - #define FxaaSat(x) clamp(x, 0.0, 1.0) - #define FxaaTex sampler2D -#else - #define FxaaBool bool - #define FxaaDiscard clip(-1) - #define FxaaFloat float - #define FxaaFloat2 float2 - #define FxaaFloat3 float3 - #define FxaaFloat4 float4 - #define FxaaHalf half - #define FxaaHalf2 half2 - #define FxaaHalf3 half3 - #define FxaaHalf4 half4 - #define FxaaSat(x) saturate(x) -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_GLSL_120 == 1) - // Requires, - // #version 120 - // And at least, - // #extension GL_EXT_gpu_shader4 : enable - // (or set FXAA_FAST_PIXEL_OFFSET 1 to work like DX9) - #define FxaaTexTop(t, p) texture2DLod(t, p, 0.0) - #if (FXAA_FAST_PIXEL_OFFSET == 1) - #define FxaaTexOff(t, p, o, r) texture2DLodOffset(t, p, 0.0, o) - #else - #define FxaaTexOff(t, p, o, r) texture2DLod(t, p + (o * r), 0.0) - #endif - #if (FXAA_GATHER4_ALPHA == 1) - // use #extension GL_ARB_gpu_shader5 : enable - #define FxaaTexAlpha4(t, p) textureGather(t, p, 3) - #define FxaaTexOffAlpha4(t, p, o) textureGatherOffset(t, p, o, 3) - #define FxaaTexGreen4(t, p) textureGather(t, p, 1) - #define FxaaTexOffGreen4(t, p, o) textureGatherOffset(t, p, o, 1) - #endif -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_GLSL_130 == 1) - // Requires "#version 130" or better - #define FxaaTexTop(t, p) textureLod(t, p, 0.0) - #define FxaaTexOff(t, p, o, r) textureLodOffset(t, p, 0.0, o) - #if (FXAA_GATHER4_ALPHA == 1) - // use #extension GL_ARB_gpu_shader5 : enable - #define FxaaTexAlpha4(t, p) textureGather(t, p, 3) - #define FxaaTexOffAlpha4(t, p, o) textureGatherOffset(t, p, o, 3) - #define FxaaTexGreen4(t, p) textureGather(t, p, 1) - #define FxaaTexOffGreen4(t, p, o) textureGatherOffset(t, p, o, 1) - #endif -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_HLSL_3 == 1) || (FXAA_360 == 1) || (FXAA_PS3 == 1) - #define FxaaInt2 float2 - #define FxaaTex sampler2D - #define FxaaTexTop(t, p) tex2Dlod(t, float4(p, 0.0, 0.0)) - #define FxaaTexOff(t, p, o, r) tex2Dlod(t, float4(p + (o * r), 0, 0)) -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_HLSL_4 == 1) - #define FxaaInt2 int2 - struct FxaaTex { SamplerState smpl; Texture2D tex; }; - #define FxaaTexTop(t, p) t.tex.SampleLevel(t.smpl, p, 0.0) - #define FxaaTexOff(t, p, o, r) t.tex.SampleLevel(t.smpl, p, 0.0, o) -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_HLSL_5 == 1) - #define FxaaInt2 int2 - struct FxaaTex { SamplerState smpl; Texture2D tex; }; - #define FxaaTexTop(t, p) t.tex.SampleLevel(t.smpl, p, 0.0) - #define FxaaTexOff(t, p, o, r) t.tex.SampleLevel(t.smpl, p, 0.0, o) - #define FxaaTexAlpha4(t, p) t.tex.GatherAlpha(t.smpl, p) - #define FxaaTexOffAlpha4(t, p, o) t.tex.GatherAlpha(t.smpl, p, o) - #define FxaaTexGreen4(t, p) t.tex.GatherGreen(t.smpl, p) - #define FxaaTexOffGreen4(t, p, o) t.tex.GatherGreen(t.smpl, p, o) -#endif - - -/*============================================================================ - GREEN AS LUMA OPTION SUPPORT FUNCTION -============================================================================*/ -#if (FXAA_GREEN_AS_LUMA == 0) - //FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return rgba.w; } - FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return dot(rgba.rgb, FxaaFloat3(0.299, 0.587, 0.114)); } -#else - FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return rgba.y; } -#endif - - - - -/*============================================================================ - - FXAA3 QUALITY - PC - -============================================================================*/ -#if (FXAA_PC == 1) -/*--------------------------------------------------------------------------*/ -FxaaFloat4 FxaaPixelShader( - // - // Use noperspective interpolation here (turn off perspective interpolation). - // {xy} = center of pixel - FxaaFloat2 pos, - // - // Used only for FXAA Console, and not used on the 360 version. - // Use noperspective interpolation here (turn off perspective interpolation). - // {xy__} = upper left of pixel - // {__zw} = lower right of pixel - FxaaFloat4 fxaaConsolePosPos, - // - // Input color texture. - // {rgb_} = color in linear or perceptual color space - // if (FXAA_GREEN_AS_LUMA == 0) - // {___a} = luma in perceptual color space (not linear) - FxaaTex tex, - // - // Only used on the optimized 360 version of FXAA Console. - // For everything but 360, just use the same input here as for "tex". - // For 360, same texture, just alias with a 2nd sampler. - // This sampler needs to have an exponent bias of -1. - FxaaTex fxaaConsole360TexExpBiasNegOne, - // - // Only used on the optimized 360 version of FXAA Console. - // For everything but 360, just use the same input here as for "tex". - // For 360, same texture, just alias with a 3nd sampler. - // This sampler needs to have an exponent bias of -2. - FxaaTex fxaaConsole360TexExpBiasNegTwo, - // - // Only used on FXAA Quality. - // This must be from a constant/uniform. - // {x_} = 1.0/screenWidthInPixels - // {_y} = 1.0/screenHeightInPixels - FxaaFloat2 fxaaQualityRcpFrame, - // - // Only used on FXAA Console. - // This must be from a constant/uniform. - // This effects sub-pixel AA quality and inversely sharpness. - // Where N ranges between, - // N = 0.50 (default) - // N = 0.33 (sharper) - // {x___} = -N/screenWidthInPixels - // {_y__} = -N/screenHeightInPixels - // {__z_} = N/screenWidthInPixels - // {___w} = N/screenHeightInPixels - FxaaFloat4 fxaaConsoleRcpFrameOpt, - // - // Only used on FXAA Console. - // Not used on 360, but used on PS3 and PC. - // This must be from a constant/uniform. - // {x___} = -2.0/screenWidthInPixels - // {_y__} = -2.0/screenHeightInPixels - // {__z_} = 2.0/screenWidthInPixels - // {___w} = 2.0/screenHeightInPixels - FxaaFloat4 fxaaConsoleRcpFrameOpt2, - // - // Only used on FXAA Console. - // Only used on 360 in place of fxaaConsoleRcpFrameOpt2. - // This must be from a constant/uniform. - // {x___} = 8.0/screenWidthInPixels - // {_y__} = 8.0/screenHeightInPixels - // {__z_} = -4.0/screenWidthInPixels - // {___w} = -4.0/screenHeightInPixels - FxaaFloat4 fxaaConsole360RcpFrameOpt2, - // - // Only used on FXAA Quality. - // This used to be the FXAA_QUALITY__SUBPIX define. - // It is here now to allow easier tuning. - // Choose the amount of sub-pixel aliasing removal. - // This can effect sharpness. - // 1.00 - upper limit (softer) - // 0.75 - default amount of filtering - // 0.50 - lower limit (sharper, less sub-pixel aliasing removal) - // 0.25 - almost off - // 0.00 - completely off - FxaaFloat fxaaQualitySubpix, - // - // Only used on FXAA Quality. - // This used to be the FXAA_QUALITY__EDGE_THRESHOLD define. - // It is here now to allow easier tuning. - // The minimum amount of local contrast required to apply algorithm. - // 0.333 - too little (faster) - // 0.250 - low quality - // 0.166 - default - // 0.125 - high quality - // 0.063 - overkill (slower) - FxaaFloat fxaaQualityEdgeThreshold, - // - // Only used on FXAA Quality. - // This used to be the FXAA_QUALITY__EDGE_THRESHOLD_MIN define. - // It is here now to allow easier tuning. - // Trims the algorithm from processing darks. - // 0.0833 - upper limit (default, the start of visible unfiltered edges) - // 0.0625 - high quality (faster) - // 0.0312 - visible limit (slower) - // Special notes when using FXAA_GREEN_AS_LUMA, - // Likely want to set this to zero. - // As colors that are mostly not-green - // will appear very dark in the green channel! - // Tune by looking at mostly non-green content, - // then start at zero and increase until aliasing is a problem. - FxaaFloat fxaaQualityEdgeThresholdMin, - // - // Only used on FXAA Console. - // This used to be the FXAA_CONSOLE__EDGE_SHARPNESS define. - // It is here now to allow easier tuning. - // This does not effect PS3, as this needs to be compiled in. - // Use FXAA_CONSOLE__PS3_EDGE_SHARPNESS for PS3. - // Due to the PS3 being ALU bound, - // there are only three safe values here: 2 and 4 and 8. - // These options use the shaders ability to a free *|/ by 2|4|8. - // For all other platforms can be a non-power of two. - // 8.0 is sharper (default!!!) - // 4.0 is softer - // 2.0 is really soft (good only for vector graphics inputs) - FxaaFloat fxaaConsoleEdgeSharpness, - // - // Only used on FXAA Console. - // This used to be the FXAA_CONSOLE__EDGE_THRESHOLD define. - // It is here now to allow easier tuning. - // This does not effect PS3, as this needs to be compiled in. - // Use FXAA_CONSOLE__PS3_EDGE_THRESHOLD for PS3. - // Due to the PS3 being ALU bound, - // there are only two safe values here: 1/4 and 1/8. - // These options use the shaders ability to a free *|/ by 2|4|8. - // The console setting has a different mapping than the quality setting. - // Other platforms can use other values. - // 0.125 leaves less aliasing, but is softer (default!!!) - // 0.25 leaves more aliasing, and is sharper - FxaaFloat fxaaConsoleEdgeThreshold, - // - // Only used on FXAA Console. - // This used to be the FXAA_CONSOLE__EDGE_THRESHOLD_MIN define. - // It is here now to allow easier tuning. - // Trims the algorithm from processing darks. - // The console setting has a different mapping than the quality setting. - // This only applies when FXAA_EARLY_EXIT is 1. - // This does not apply to PS3, - // PS3 was simplified to avoid more shader instructions. - // 0.06 - faster but more aliasing in darks - // 0.05 - default - // 0.04 - slower and less aliasing in darks - // Special notes when using FXAA_GREEN_AS_LUMA, - // Likely want to set this to zero. - // As colors that are mostly not-green - // will appear very dark in the green channel! - // Tune by looking at mostly non-green content, - // then start at zero and increase until aliasing is a problem. - FxaaFloat fxaaConsoleEdgeThresholdMin, - // - // Extra constants for 360 FXAA Console only. - // Use zeros or anything else for other platforms. - // These must be in physical constant registers and NOT immedates. - // Immedates will result in compiler un-optimizing. - // {xyzw} = float4(1.0, -1.0, 0.25, -0.25) - FxaaFloat4 fxaaConsole360ConstDir -) { -/*--------------------------------------------------------------------------*/ - FxaaFloat2 posM; - posM.x = pos.x; - posM.y = pos.y; - #if (FXAA_GATHER4_ALPHA == 1) - #if (FXAA_DISCARD == 0) - FxaaFloat4 rgbyM = FxaaTexTop(tex, posM); - #if (FXAA_GREEN_AS_LUMA == 0) - #define lumaM dot(rgbyM.rgb, FxaaFloat3(0.299, 0.587, 0.114)) - #else - #define lumaM rgbyM.y - #endif - #endif - #if (FXAA_GREEN_AS_LUMA == 0) - FxaaFloat4 luma4A = FxaaTexAlpha4(tex, posM); - FxaaFloat4 luma4B = FxaaTexOffAlpha4(tex, posM, FxaaInt2(-1, -1)); - #else - FxaaFloat4 luma4A = FxaaTexGreen4(tex, posM); - FxaaFloat4 luma4B = FxaaTexOffGreen4(tex, posM, FxaaInt2(-1, -1)); - #endif - #if (FXAA_DISCARD == 1) - #define lumaM luma4A.w - #endif - #define lumaE luma4A.z - #define lumaS luma4A.x - #define lumaSE luma4A.y - #define lumaNW luma4B.w - #define lumaN luma4B.z - #define lumaW luma4B.x - #else - FxaaFloat4 rgbyM = FxaaTexTop(tex, posM); - #if (FXAA_GREEN_AS_LUMA == 0) - #define lumaM dot(rgbyM.rgb, FxaaFloat3(0.299, 0.587, 0.114)) - #else - #define lumaM rgbyM.y - #endif - FxaaFloat lumaS = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 0, 1), fxaaQualityRcpFrame.xy)); - FxaaFloat lumaE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1, 0), fxaaQualityRcpFrame.xy)); - FxaaFloat lumaN = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 0,-1), fxaaQualityRcpFrame.xy)); - FxaaFloat lumaW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 0), fxaaQualityRcpFrame.xy)); - #endif -/*--------------------------------------------------------------------------*/ - FxaaFloat maxSM = max(lumaS, lumaM); - FxaaFloat minSM = min(lumaS, lumaM); - FxaaFloat maxESM = max(lumaE, maxSM); - FxaaFloat minESM = min(lumaE, minSM); - FxaaFloat maxWN = max(lumaN, lumaW); - FxaaFloat minWN = min(lumaN, lumaW); - FxaaFloat rangeMax = max(maxWN, maxESM); - FxaaFloat rangeMin = min(minWN, minESM); - FxaaFloat rangeMaxScaled = rangeMax * fxaaQualityEdgeThreshold; - FxaaFloat range = rangeMax - rangeMin; - FxaaFloat rangeMaxClamped = max(fxaaQualityEdgeThresholdMin, rangeMaxScaled); - FxaaBool earlyExit = range < rangeMaxClamped; -/*--------------------------------------------------------------------------*/ - if(earlyExit) - #if (FXAA_DISCARD == 1) - FxaaDiscard; - #else - return rgbyM; - #endif -/*--------------------------------------------------------------------------*/ - #if (FXAA_GATHER4_ALPHA == 0) - FxaaFloat lumaNW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1,-1), fxaaQualityRcpFrame.xy)); - FxaaFloat lumaSE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1, 1), fxaaQualityRcpFrame.xy)); - FxaaFloat lumaNE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1,-1), fxaaQualityRcpFrame.xy)); - FxaaFloat lumaSW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 1), fxaaQualityRcpFrame.xy)); - #else - FxaaFloat lumaNE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(1, -1), fxaaQualityRcpFrame.xy)); - FxaaFloat lumaSW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 1), fxaaQualityRcpFrame.xy)); - #endif -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaNS = lumaN + lumaS; - FxaaFloat lumaWE = lumaW + lumaE; - FxaaFloat subpixRcpRange = 1.0/range; - FxaaFloat subpixNSWE = lumaNS + lumaWE; - FxaaFloat edgeHorz1 = (-2.0 * lumaM) + lumaNS; - FxaaFloat edgeVert1 = (-2.0 * lumaM) + lumaWE; -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaNESE = lumaNE + lumaSE; - FxaaFloat lumaNWNE = lumaNW + lumaNE; - FxaaFloat edgeHorz2 = (-2.0 * lumaE) + lumaNESE; - FxaaFloat edgeVert2 = (-2.0 * lumaN) + lumaNWNE; -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaNWSW = lumaNW + lumaSW; - FxaaFloat lumaSWSE = lumaSW + lumaSE; - FxaaFloat edgeHorz4 = (abs(edgeHorz1) * 2.0) + abs(edgeHorz2); - FxaaFloat edgeVert4 = (abs(edgeVert1) * 2.0) + abs(edgeVert2); - FxaaFloat edgeHorz3 = (-2.0 * lumaW) + lumaNWSW; - FxaaFloat edgeVert3 = (-2.0 * lumaS) + lumaSWSE; - FxaaFloat edgeHorz = abs(edgeHorz3) + edgeHorz4; - FxaaFloat edgeVert = abs(edgeVert3) + edgeVert4; -/*--------------------------------------------------------------------------*/ - FxaaFloat subpixNWSWNESE = lumaNWSW + lumaNESE; - FxaaFloat lengthSign = fxaaQualityRcpFrame.x; - FxaaBool horzSpan = edgeHorz >= edgeVert; - FxaaFloat subpixA = subpixNSWE * 2.0 + subpixNWSWNESE; -/*--------------------------------------------------------------------------*/ - if(!horzSpan) lumaN = lumaW; - if(!horzSpan) lumaS = lumaE; - if(horzSpan) lengthSign = fxaaQualityRcpFrame.y; - FxaaFloat subpixB = (subpixA * (1.0/12.0)) - lumaM; -/*--------------------------------------------------------------------------*/ - FxaaFloat gradientN = lumaN - lumaM; - FxaaFloat gradientS = lumaS - lumaM; - FxaaFloat lumaNN = lumaN + lumaM; - FxaaFloat lumaSS = lumaS + lumaM; - FxaaBool pairN = abs(gradientN) >= abs(gradientS); - FxaaFloat gradient = max(abs(gradientN), abs(gradientS)); - if(pairN) lengthSign = -lengthSign; - FxaaFloat subpixC = FxaaSat(abs(subpixB) * subpixRcpRange); -/*--------------------------------------------------------------------------*/ - FxaaFloat2 posB; - posB.x = posM.x; - posB.y = posM.y; - FxaaFloat2 offNP; - offNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x; - offNP.y = ( horzSpan) ? 0.0 : fxaaQualityRcpFrame.y; - if(!horzSpan) posB.x += lengthSign * 0.5; - if( horzSpan) posB.y += lengthSign * 0.5; -/*--------------------------------------------------------------------------*/ - FxaaFloat2 posN; - posN.x = posB.x - offNP.x * FXAA_QUALITY__P0; - posN.y = posB.y - offNP.y * FXAA_QUALITY__P0; - FxaaFloat2 posP; - posP.x = posB.x + offNP.x * FXAA_QUALITY__P0; - posP.y = posB.y + offNP.y * FXAA_QUALITY__P0; - FxaaFloat subpixD = ((-2.0)*subpixC) + 3.0; - FxaaFloat lumaEndN = FxaaLuma(FxaaTexTop(tex, posN)); - FxaaFloat subpixE = subpixC * subpixC; - FxaaFloat lumaEndP = FxaaLuma(FxaaTexTop(tex, posP)); -/*--------------------------------------------------------------------------*/ - if(!pairN) lumaNN = lumaSS; - FxaaFloat gradientScaled = gradient * 1.0/4.0; - FxaaFloat lumaMM = lumaM - lumaNN * 0.5; - FxaaFloat subpixF = subpixD * subpixE; - FxaaBool lumaMLTZero = lumaMM < 0.0; -/*--------------------------------------------------------------------------*/ - lumaEndN -= lumaNN * 0.5; - lumaEndP -= lumaNN * 0.5; - FxaaBool doneN = abs(lumaEndN) >= gradientScaled; - FxaaBool doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P1; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P1; - FxaaBool doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P1; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P1; -/*--------------------------------------------------------------------------*/ - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P2; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P2; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P2; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P2; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 3) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P3; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P3; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P3; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P3; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 4) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P4; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P4; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P4; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P4; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 5) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P5; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P5; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P5; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P5; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 6) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P6; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P6; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P6; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P6; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 7) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P7; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P7; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P7; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P7; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 8) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P8; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P8; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P8; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P8; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 9) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P9; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P9; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P9; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P9; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 10) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P10; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P10; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P10; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P10; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 11) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P11; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P11; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P11; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P11; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 12) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P12; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P12; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P12; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P12; -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } -/*--------------------------------------------------------------------------*/ - FxaaFloat dstN = posM.x - posN.x; - FxaaFloat dstP = posP.x - posM.x; - if(!horzSpan) dstN = posM.y - posN.y; - if(!horzSpan) dstP = posP.y - posM.y; -/*--------------------------------------------------------------------------*/ - FxaaBool goodSpanN = (lumaEndN < 0.0) != lumaMLTZero; - FxaaFloat spanLength = (dstP + dstN); - FxaaBool goodSpanP = (lumaEndP < 0.0) != lumaMLTZero; - FxaaFloat spanLengthRcp = 1.0/spanLength; -/*--------------------------------------------------------------------------*/ - FxaaBool directionN = dstN < dstP; - FxaaFloat dst = min(dstN, dstP); - FxaaBool goodSpan = directionN ? goodSpanN : goodSpanP; - FxaaFloat subpixG = subpixF * subpixF; - FxaaFloat pixelOffset = (dst * (-spanLengthRcp)) + 0.5; - FxaaFloat subpixH = subpixG * fxaaQualitySubpix; -/*--------------------------------------------------------------------------*/ - FxaaFloat pixelOffsetGood = goodSpan ? pixelOffset : 0.0; - FxaaFloat pixelOffsetSubpix = max(pixelOffsetGood, subpixH); - if(!horzSpan) posM.x += pixelOffsetSubpix * lengthSign; - if( horzSpan) posM.y += pixelOffsetSubpix * lengthSign; - #if (FXAA_DISCARD == 1) - return FxaaTexTop(tex, posM); - #else - //return FxaaFloat4(FxaaTexTop(tex, posM).xyz, lumaM); - return FxaaFloat4(FxaaTexTop(tex, posM)); - #endif -} -/*==========================================================================*/ -#endif - - - - -/*============================================================================ - - FXAA3 CONSOLE - PC VERSION - ------------------------------------------------------------------------------- -Instead of using this on PC, I'd suggest just using FXAA Quality with - #define FXAA_QUALITY__PRESET 10 -Or - #define FXAA_QUALITY__PRESET 20 -Either are higher qualilty and almost as fast as this on modern PC GPUs. -============================================================================*/ -#if (FXAA_PC_CONSOLE == 1) -/*--------------------------------------------------------------------------*/ -FxaaFloat4 FxaaPixelShader( - // See FXAA Quality FxaaPixelShader() source for docs on Inputs! - FxaaFloat2 pos, - FxaaFloat4 fxaaConsolePosPos, - FxaaTex tex, - FxaaTex fxaaConsole360TexExpBiasNegOne, - FxaaTex fxaaConsole360TexExpBiasNegTwo, - FxaaFloat2 fxaaQualityRcpFrame, - FxaaFloat4 fxaaConsoleRcpFrameOpt, - FxaaFloat4 fxaaConsoleRcpFrameOpt2, - FxaaFloat4 fxaaConsole360RcpFrameOpt2, - FxaaFloat fxaaQualitySubpix, - FxaaFloat fxaaQualityEdgeThreshold, - FxaaFloat fxaaQualityEdgeThresholdMin, - FxaaFloat fxaaConsoleEdgeSharpness, - FxaaFloat fxaaConsoleEdgeThreshold, - FxaaFloat fxaaConsoleEdgeThresholdMin, - FxaaFloat4 fxaaConsole360ConstDir -) { -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaNw = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.xy)); - FxaaFloat lumaSw = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.xw)); - FxaaFloat lumaNe = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.zy)); - FxaaFloat lumaSe = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.zw)); -/*--------------------------------------------------------------------------*/ - FxaaFloat4 rgbyM = FxaaTexTop(tex, pos.xy); - #if (FXAA_GREEN_AS_LUMA == 0) - FxaaFloat lumaM = rgbyM.w; - #else - FxaaFloat lumaM = rgbyM.y; - #endif -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaMaxNwSw = max(lumaNw, lumaSw); - lumaNe += 1.0/384.0; - FxaaFloat lumaMinNwSw = min(lumaNw, lumaSw); -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaMaxNeSe = max(lumaNe, lumaSe); - FxaaFloat lumaMinNeSe = min(lumaNe, lumaSe); -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaMax = max(lumaMaxNeSe, lumaMaxNwSw); - FxaaFloat lumaMin = min(lumaMinNeSe, lumaMinNwSw); -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaMaxScaled = lumaMax * fxaaConsoleEdgeThreshold; -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaMinM = min(lumaMin, lumaM); - FxaaFloat lumaMaxScaledClamped = max(fxaaConsoleEdgeThresholdMin, lumaMaxScaled); - FxaaFloat lumaMaxM = max(lumaMax, lumaM); - FxaaFloat dirSwMinusNe = lumaSw - lumaNe; - FxaaFloat lumaMaxSubMinM = lumaMaxM - lumaMinM; - FxaaFloat dirSeMinusNw = lumaSe - lumaNw; - if(lumaMaxSubMinM < lumaMaxScaledClamped) return rgbyM; -/*--------------------------------------------------------------------------*/ - FxaaFloat2 dir; - dir.x = dirSwMinusNe + dirSeMinusNw; - dir.y = dirSwMinusNe - dirSeMinusNw; -/*--------------------------------------------------------------------------*/ - FxaaFloat2 dir1 = normalize(dir.xy); - FxaaFloat4 rgbyN1 = FxaaTexTop(tex, pos.xy - dir1 * fxaaConsoleRcpFrameOpt.zw); - FxaaFloat4 rgbyP1 = FxaaTexTop(tex, pos.xy + dir1 * fxaaConsoleRcpFrameOpt.zw); -/*--------------------------------------------------------------------------*/ - FxaaFloat dirAbsMinTimesC = min(abs(dir1.x), abs(dir1.y)) * fxaaConsoleEdgeSharpness; - FxaaFloat2 dir2 = clamp(dir1.xy / dirAbsMinTimesC, -2.0, 2.0); -/*--------------------------------------------------------------------------*/ - FxaaFloat4 rgbyN2 = FxaaTexTop(tex, pos.xy - dir2 * fxaaConsoleRcpFrameOpt2.zw); - FxaaFloat4 rgbyP2 = FxaaTexTop(tex, pos.xy + dir2 * fxaaConsoleRcpFrameOpt2.zw); -/*--------------------------------------------------------------------------*/ - FxaaFloat4 rgbyA = rgbyN1 + rgbyP1; - FxaaFloat4 rgbyB = ((rgbyN2 + rgbyP2) * 0.25) + (rgbyA * 0.25); -/*--------------------------------------------------------------------------*/ - #if (FXAA_GREEN_AS_LUMA == 0) - FxaaBool twoTap = (rgbyB.w < lumaMin) || (rgbyB.w > lumaMax); - #else - FxaaBool twoTap = (rgbyB.y < lumaMin) || (rgbyB.y > lumaMax); - #endif - if(twoTap) rgbyB.xyz = rgbyA.xyz * 0.5; - return rgbyB; } -/*==========================================================================*/ -#endif - - - -/*============================================================================ - - FXAA3 CONSOLE - 360 PIXEL SHADER - ------------------------------------------------------------------------------- -This optimized version thanks to suggestions from Andy Luedke. -Should be fully tex bound in all cases. -As of the FXAA 3.11 release, I have still not tested this code, -however I fixed a bug which was in both FXAA 3.9 and FXAA 3.10. -And note this is replacing the old unoptimized version. -If it does not work, please let me know so I can fix it. -============================================================================*/ -#if (FXAA_360 == 1) -/*--------------------------------------------------------------------------*/ -[reduceTempRegUsage(4)] -float4 FxaaPixelShader( - // See FXAA Quality FxaaPixelShader() source for docs on Inputs! - FxaaFloat2 pos, - FxaaFloat4 fxaaConsolePosPos, - FxaaTex tex, - FxaaTex fxaaConsole360TexExpBiasNegOne, - FxaaTex fxaaConsole360TexExpBiasNegTwo, - FxaaFloat2 fxaaQualityRcpFrame, - FxaaFloat4 fxaaConsoleRcpFrameOpt, - FxaaFloat4 fxaaConsoleRcpFrameOpt2, - FxaaFloat4 fxaaConsole360RcpFrameOpt2, - FxaaFloat fxaaQualitySubpix, - FxaaFloat fxaaQualityEdgeThreshold, - FxaaFloat fxaaQualityEdgeThresholdMin, - FxaaFloat fxaaConsoleEdgeSharpness, - FxaaFloat fxaaConsoleEdgeThreshold, - FxaaFloat fxaaConsoleEdgeThresholdMin, - FxaaFloat4 fxaaConsole360ConstDir -) { -/*--------------------------------------------------------------------------*/ - float4 lumaNwNeSwSe; - #if (FXAA_GREEN_AS_LUMA == 0) - asm { - tfetch2D lumaNwNeSwSe.w___, tex, pos.xy, OffsetX = -0.5, OffsetY = -0.5, UseComputedLOD=false - tfetch2D lumaNwNeSwSe._w__, tex, pos.xy, OffsetX = 0.5, OffsetY = -0.5, UseComputedLOD=false - tfetch2D lumaNwNeSwSe.__w_, tex, pos.xy, OffsetX = -0.5, OffsetY = 0.5, UseComputedLOD=false - tfetch2D lumaNwNeSwSe.___w, tex, pos.xy, OffsetX = 0.5, OffsetY = 0.5, UseComputedLOD=false - }; - #else - asm { - tfetch2D lumaNwNeSwSe.y___, tex, pos.xy, OffsetX = -0.5, OffsetY = -0.5, UseComputedLOD=false - tfetch2D lumaNwNeSwSe._y__, tex, pos.xy, OffsetX = 0.5, OffsetY = -0.5, UseComputedLOD=false - tfetch2D lumaNwNeSwSe.__y_, tex, pos.xy, OffsetX = -0.5, OffsetY = 0.5, UseComputedLOD=false - tfetch2D lumaNwNeSwSe.___y, tex, pos.xy, OffsetX = 0.5, OffsetY = 0.5, UseComputedLOD=false - }; - #endif -/*--------------------------------------------------------------------------*/ - lumaNwNeSwSe.y += 1.0/384.0; - float2 lumaMinTemp = min(lumaNwNeSwSe.xy, lumaNwNeSwSe.zw); - float2 lumaMaxTemp = max(lumaNwNeSwSe.xy, lumaNwNeSwSe.zw); - float lumaMin = min(lumaMinTemp.x, lumaMinTemp.y); - float lumaMax = max(lumaMaxTemp.x, lumaMaxTemp.y); -/*--------------------------------------------------------------------------*/ - float4 rgbyM = tex2Dlod(tex, float4(pos.xy, 0.0, 0.0)); - #if (FXAA_GREEN_AS_LUMA == 0) - float lumaMinM = min(lumaMin, rgbyM.w); - float lumaMaxM = max(lumaMax, rgbyM.w); - #else - float lumaMinM = min(lumaMin, rgbyM.y); - float lumaMaxM = max(lumaMax, rgbyM.y); - #endif - if((lumaMaxM - lumaMinM) < max(fxaaConsoleEdgeThresholdMin, lumaMax * fxaaConsoleEdgeThreshold)) return rgbyM; -/*--------------------------------------------------------------------------*/ - float2 dir; - dir.x = dot(lumaNwNeSwSe, fxaaConsole360ConstDir.yyxx); - dir.y = dot(lumaNwNeSwSe, fxaaConsole360ConstDir.xyxy); - dir = normalize(dir); -/*--------------------------------------------------------------------------*/ - float4 dir1 = dir.xyxy * fxaaConsoleRcpFrameOpt.xyzw; -/*--------------------------------------------------------------------------*/ - float4 dir2; - float dirAbsMinTimesC = min(abs(dir.x), abs(dir.y)) * fxaaConsoleEdgeSharpness; - dir2 = saturate(fxaaConsole360ConstDir.zzww * dir.xyxy / dirAbsMinTimesC + 0.5); - dir2 = dir2 * fxaaConsole360RcpFrameOpt2.xyxy + fxaaConsole360RcpFrameOpt2.zwzw; -/*--------------------------------------------------------------------------*/ - float4 rgbyN1 = tex2Dlod(fxaaConsole360TexExpBiasNegOne, float4(pos.xy + dir1.xy, 0.0, 0.0)); - float4 rgbyP1 = tex2Dlod(fxaaConsole360TexExpBiasNegOne, float4(pos.xy + dir1.zw, 0.0, 0.0)); - float4 rgbyN2 = tex2Dlod(fxaaConsole360TexExpBiasNegTwo, float4(pos.xy + dir2.xy, 0.0, 0.0)); - float4 rgbyP2 = tex2Dlod(fxaaConsole360TexExpBiasNegTwo, float4(pos.xy + dir2.zw, 0.0, 0.0)); -/*--------------------------------------------------------------------------*/ - float4 rgbyA = rgbyN1 + rgbyP1; - float4 rgbyB = rgbyN2 + rgbyP2 + rgbyA * 0.5; -/*--------------------------------------------------------------------------*/ - float4 rgbyR = ((FxaaLuma(rgbyB) - lumaMax) > 0.0) ? rgbyA : rgbyB; - rgbyR = ((FxaaLuma(rgbyB) - lumaMin) > 0.0) ? rgbyR : rgbyA; - return rgbyR; } -/*==========================================================================*/ -#endif - - - -/*============================================================================ - - FXAA3 CONSOLE - OPTIMIZED PS3 PIXEL SHADER (NO EARLY EXIT) - -============================================================================== -The code below does not exactly match the assembly. -I have a feeling that 12 cycles is possible, but was not able to get there. -Might have to increase register count to get full performance. -Note this shader does not use perspective interpolation. - -Use the following cgc options, - - --fenable-bx2 --fastmath --fastprecision --nofloatbindings - ------------------------------------------------------------------------------- - NVSHADERPERF OUTPUT ------------------------------------------------------------------------------- -For reference and to aid in debug, output of NVShaderPerf should match this, - -Shader to schedule: - 0: texpkb h0.w(TRUE), v5.zyxx, #0 - 2: addh h2.z(TRUE), h0.w, constant(0.001953, 0.000000, 0.000000, 0.000000).x - 4: texpkb h0.w(TRUE), v5.xwxx, #0 - 6: addh h0.z(TRUE), -h2, h0.w - 7: texpkb h1.w(TRUE), v5, #0 - 9: addh h0.x(TRUE), h0.z, -h1.w - 10: addh h3.w(TRUE), h0.z, h1 - 11: texpkb h2.w(TRUE), v5.zwzz, #0 - 13: addh h0.z(TRUE), h3.w, -h2.w - 14: addh h0.x(TRUE), h2.w, h0 - 15: nrmh h1.xz(TRUE), h0_n - 16: minh_m8 h0.x(TRUE), |h1|, |h1.z| - 17: maxh h4.w(TRUE), h0, h1 - 18: divx h2.xy(TRUE), h1_n.xzzw, h0_n - 19: movr r1.zw(TRUE), v4.xxxy - 20: madr r2.xz(TRUE), -h1, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).zzww, r1.zzww - 22: minh h5.w(TRUE), h0, h1 - 23: texpkb h0(TRUE), r2.xzxx, #0 - 25: madr r0.zw(TRUE), h1.xzxz, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w), r1 - 27: maxh h4.x(TRUE), h2.z, h2.w - 28: texpkb h1(TRUE), r0.zwzz, #0 - 30: addh_d2 h1(TRUE), h0, h1 - 31: madr r0.xy(TRUE), -h2, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).xyxx, r1.zwzz - 33: texpkb h0(TRUE), r0, #0 - 35: minh h4.z(TRUE), h2, h2.w - 36: fenct TRUE - 37: madr r1.xy(TRUE), h2, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).xyxx, r1.zwzz - 39: texpkb h2(TRUE), r1, #0 - 41: addh_d2 h0(TRUE), h0, h2 - 42: maxh h2.w(TRUE), h4, h4.x - 43: minh h2.x(TRUE), h5.w, h4.z - 44: addh_d2 h0(TRUE), h0, h1 - 45: slth h2.x(TRUE), h0.w, h2 - 46: sgth h2.w(TRUE), h0, h2 - 47: movh h0(TRUE), h0 - 48: addx.c0 rc(TRUE), h2, h2.w - 49: movh h0(c0.NE.x), h1 - -IPU0 ------ Simplified schedule: -------- -Pass | Unit | uOp | PC: Op ------+--------+------+------------------------- - 1 | SCT0/1 | mov | 0: TXLr h0.w, g[TEX1].zyxx, const.xxxx, TEX0; - | TEX | txl | 0: TXLr h0.w, g[TEX1].zyxx, const.xxxx, TEX0; - | SCB1 | add | 2: ADDh h2.z, h0.--w-, const.--x-; - | | | - 2 | SCT0/1 | mov | 4: TXLr h0.w, g[TEX1].xwxx, const.xxxx, TEX0; - | TEX | txl | 4: TXLr h0.w, g[TEX1].xwxx, const.xxxx, TEX0; - | SCB1 | add | 6: ADDh h0.z,-h2, h0.--w-; - | | | - 3 | SCT0/1 | mov | 7: TXLr h1.w, g[TEX1], const.xxxx, TEX0; - | TEX | txl | 7: TXLr h1.w, g[TEX1], const.xxxx, TEX0; - | SCB0 | add | 9: ADDh h0.x, h0.z---,-h1.w---; - | SCB1 | add | 10: ADDh h3.w, h0.---z, h1; - | | | - 4 | SCT0/1 | mov | 11: TXLr h2.w, g[TEX1].zwzz, const.xxxx, TEX0; - | TEX | txl | 11: TXLr h2.w, g[TEX1].zwzz, const.xxxx, TEX0; - | SCB0 | add | 14: ADDh h0.x, h2.w---, h0; - | SCB1 | add | 13: ADDh h0.z, h3.--w-,-h2.--w-; - | | | - 5 | SCT1 | mov | 15: NRMh h1.xz, h0; - | SRB | nrm | 15: NRMh h1.xz, h0; - | SCB0 | min | 16: MINh*8 h0.x, |h1|, |h1.z---|; - | SCB1 | max | 17: MAXh h4.w, h0, h1; - | | | - 6 | SCT0 | div | 18: DIVx h2.xy, h1.xz--, h0; - | SCT1 | mov | 19: MOVr r1.zw, g[TEX0].--xy; - | SCB0 | mad | 20: MADr r2.xz,-h1, const.z-w-, r1.z-w-; - | SCB1 | min | 22: MINh h5.w, h0, h1; - | | | - 7 | SCT0/1 | mov | 23: TXLr h0, r2.xzxx, const.xxxx, TEX0; - | TEX | txl | 23: TXLr h0, r2.xzxx, const.xxxx, TEX0; - | SCB0 | max | 27: MAXh h4.x, h2.z---, h2.w---; - | SCB1 | mad | 25: MADr r0.zw, h1.--xz, const, r1; - | | | - 8 | SCT0/1 | mov | 28: TXLr h1, r0.zwzz, const.xxxx, TEX0; - | TEX | txl | 28: TXLr h1, r0.zwzz, const.xxxx, TEX0; - | SCB0/1 | add | 30: ADDh/2 h1, h0, h1; - | | | - 9 | SCT0 | mad | 31: MADr r0.xy,-h2, const.xy--, r1.zw--; - | SCT1 | mov | 33: TXLr h0, r0, const.zzzz, TEX0; - | TEX | txl | 33: TXLr h0, r0, const.zzzz, TEX0; - | SCB1 | min | 35: MINh h4.z, h2, h2.--w-; - | | | - 10 | SCT0 | mad | 37: MADr r1.xy, h2, const.xy--, r1.zw--; - | SCT1 | mov | 39: TXLr h2, r1, const.zzzz, TEX0; - | TEX | txl | 39: TXLr h2, r1, const.zzzz, TEX0; - | SCB0/1 | add | 41: ADDh/2 h0, h0, h2; - | | | - 11 | SCT0 | min | 43: MINh h2.x, h5.w---, h4.z---; - | SCT1 | max | 42: MAXh h2.w, h4, h4.---x; - | SCB0/1 | add | 44: ADDh/2 h0, h0, h1; - | | | - 12 | SCT0 | set | 45: SLTh h2.x, h0.w---, h2; - | SCT1 | set | 46: SGTh h2.w, h0, h2; - | SCB0/1 | mul | 47: MOVh h0, h0; - | | | - 13 | SCT0 | mad | 48: ADDxc0_s rc, h2, h2.w---; - | SCB0/1 | mul | 49: MOVh h0(NE0.xxxx), h1; - -Pass SCT TEX SCB - 1: 0% 100% 25% - 2: 0% 100% 25% - 3: 0% 100% 50% - 4: 0% 100% 50% - 5: 0% 0% 50% - 6: 100% 0% 75% - 7: 0% 100% 75% - 8: 0% 100% 100% - 9: 0% 100% 25% - 10: 0% 100% 100% - 11: 50% 0% 100% - 12: 50% 0% 100% - 13: 25% 0% 100% - -MEAN: 17% 61% 67% - -Pass SCT0 SCT1 TEX SCB0 SCB1 - 1: 0% 0% 100% 0% 100% - 2: 0% 0% 100% 0% 100% - 3: 0% 0% 100% 100% 100% - 4: 0% 0% 100% 100% 100% - 5: 0% 0% 0% 100% 100% - 6: 100% 100% 0% 100% 100% - 7: 0% 0% 100% 100% 100% - 8: 0% 0% 100% 100% 100% - 9: 0% 0% 100% 0% 100% - 10: 0% 0% 100% 100% 100% - 11: 100% 100% 0% 100% 100% - 12: 100% 100% 0% 100% 100% - 13: 100% 0% 0% 100% 100% - -MEAN: 30% 23% 61% 76% 100% -Fragment Performance Setup: Driver RSX Compiler, GPU RSX, Flags 0x5 -Results 13 cycles, 3 r regs, 923,076,923 pixels/s -============================================================================*/ -#if (FXAA_PS3 == 1) && (FXAA_EARLY_EXIT == 0) -/*--------------------------------------------------------------------------*/ -#pragma regcount 7 -#pragma disablepc all -#pragma option O3 -#pragma option OutColorPrec=fp16 -#pragma texformat default RGBA8 -/*==========================================================================*/ -half4 FxaaPixelShader( - // See FXAA Quality FxaaPixelShader() source for docs on Inputs! - FxaaFloat2 pos, - FxaaFloat4 fxaaConsolePosPos, - FxaaTex tex, - FxaaTex fxaaConsole360TexExpBiasNegOne, - FxaaTex fxaaConsole360TexExpBiasNegTwo, - FxaaFloat2 fxaaQualityRcpFrame, - FxaaFloat4 fxaaConsoleRcpFrameOpt, - FxaaFloat4 fxaaConsoleRcpFrameOpt2, - FxaaFloat4 fxaaConsole360RcpFrameOpt2, - FxaaFloat fxaaQualitySubpix, - FxaaFloat fxaaQualityEdgeThreshold, - FxaaFloat fxaaQualityEdgeThresholdMin, - FxaaFloat fxaaConsoleEdgeSharpness, - FxaaFloat fxaaConsoleEdgeThreshold, - FxaaFloat fxaaConsoleEdgeThresholdMin, - FxaaFloat4 fxaaConsole360ConstDir -) { -/*--------------------------------------------------------------------------*/ -// (1) - half4 dir; - half4 lumaNe = h4tex2Dlod(tex, half4(fxaaConsolePosPos.zy, 0, 0)); - #if (FXAA_GREEN_AS_LUMA == 0) - lumaNe.w += half(1.0/512.0); - dir.x = -lumaNe.w; - dir.z = -lumaNe.w; - #else - lumaNe.y += half(1.0/512.0); - dir.x = -lumaNe.y; - dir.z = -lumaNe.y; - #endif -/*--------------------------------------------------------------------------*/ -// (2) - half4 lumaSw = h4tex2Dlod(tex, half4(fxaaConsolePosPos.xw, 0, 0)); - #if (FXAA_GREEN_AS_LUMA == 0) - dir.x += lumaSw.w; - dir.z += lumaSw.w; - #else - dir.x += lumaSw.y; - dir.z += lumaSw.y; - #endif -/*--------------------------------------------------------------------------*/ -// (3) - half4 lumaNw = h4tex2Dlod(tex, half4(fxaaConsolePosPos.xy, 0, 0)); - #if (FXAA_GREEN_AS_LUMA == 0) - dir.x -= lumaNw.w; - dir.z += lumaNw.w; - #else - dir.x -= lumaNw.y; - dir.z += lumaNw.y; - #endif -/*--------------------------------------------------------------------------*/ -// (4) - half4 lumaSe = h4tex2Dlod(tex, half4(fxaaConsolePosPos.zw, 0, 0)); - #if (FXAA_GREEN_AS_LUMA == 0) - dir.x += lumaSe.w; - dir.z -= lumaSe.w; - #else - dir.x += lumaSe.y; - dir.z -= lumaSe.y; - #endif -/*--------------------------------------------------------------------------*/ -// (5) - half4 dir1_pos; - dir1_pos.xy = normalize(dir.xyz).xz; - half dirAbsMinTimesC = min(abs(dir1_pos.x), abs(dir1_pos.y)) * half(FXAA_CONSOLE__PS3_EDGE_SHARPNESS); -/*--------------------------------------------------------------------------*/ -// (6) - half4 dir2_pos; - dir2_pos.xy = clamp(dir1_pos.xy / dirAbsMinTimesC, half(-2.0), half(2.0)); - dir1_pos.zw = pos.xy; - dir2_pos.zw = pos.xy; - half4 temp1N; - temp1N.xy = dir1_pos.zw - dir1_pos.xy * fxaaConsoleRcpFrameOpt.zw; -/*--------------------------------------------------------------------------*/ -// (7) - temp1N = h4tex2Dlod(tex, half4(temp1N.xy, 0.0, 0.0)); - half4 rgby1; - rgby1.xy = dir1_pos.zw + dir1_pos.xy * fxaaConsoleRcpFrameOpt.zw; -/*--------------------------------------------------------------------------*/ -// (8) - rgby1 = h4tex2Dlod(tex, half4(rgby1.xy, 0.0, 0.0)); - rgby1 = (temp1N + rgby1) * 0.5; -/*--------------------------------------------------------------------------*/ -// (9) - half4 temp2N; - temp2N.xy = dir2_pos.zw - dir2_pos.xy * fxaaConsoleRcpFrameOpt2.zw; - temp2N = h4tex2Dlod(tex, half4(temp2N.xy, 0.0, 0.0)); -/*--------------------------------------------------------------------------*/ -// (10) - half4 rgby2; - rgby2.xy = dir2_pos.zw + dir2_pos.xy * fxaaConsoleRcpFrameOpt2.zw; - rgby2 = h4tex2Dlod(tex, half4(rgby2.xy, 0.0, 0.0)); - rgby2 = (temp2N + rgby2) * 0.5; -/*--------------------------------------------------------------------------*/ -// (11) - // compilier moves these scalar ops up to other cycles - #if (FXAA_GREEN_AS_LUMA == 0) - half lumaMin = min(min(lumaNw.w, lumaSw.w), min(lumaNe.w, lumaSe.w)); - half lumaMax = max(max(lumaNw.w, lumaSw.w), max(lumaNe.w, lumaSe.w)); - #else - half lumaMin = min(min(lumaNw.y, lumaSw.y), min(lumaNe.y, lumaSe.y)); - half lumaMax = max(max(lumaNw.y, lumaSw.y), max(lumaNe.y, lumaSe.y)); - #endif - rgby2 = (rgby2 + rgby1) * 0.5; -/*--------------------------------------------------------------------------*/ -// (12) - #if (FXAA_GREEN_AS_LUMA == 0) - bool twoTapLt = rgby2.w < lumaMin; - bool twoTapGt = rgby2.w > lumaMax; - #else - bool twoTapLt = rgby2.y < lumaMin; - bool twoTapGt = rgby2.y > lumaMax; - #endif -/*--------------------------------------------------------------------------*/ -// (13) - if(twoTapLt || twoTapGt) rgby2 = rgby1; -/*--------------------------------------------------------------------------*/ - return rgby2; } -/*==========================================================================*/ -#endif - - - -/*============================================================================ - - FXAA3 CONSOLE - OPTIMIZED PS3 PIXEL SHADER (WITH EARLY EXIT) - -============================================================================== -The code mostly matches the assembly. -I have a feeling that 14 cycles is possible, but was not able to get there. -Might have to increase register count to get full performance. -Note this shader does not use perspective interpolation. - -Use the following cgc options, - - --fenable-bx2 --fastmath --fastprecision --nofloatbindings - -Use of FXAA_GREEN_AS_LUMA currently adds a cycle (16 clks). -Will look at fixing this for FXAA 3.12. ------------------------------------------------------------------------------- - NVSHADERPERF OUTPUT ------------------------------------------------------------------------------- -For reference and to aid in debug, output of NVShaderPerf should match this, - -Shader to schedule: - 0: texpkb h0.w(TRUE), v5.zyxx, #0 - 2: addh h2.y(TRUE), h0.w, constant(0.001953, 0.000000, 0.000000, 0.000000).x - 4: texpkb h1.w(TRUE), v5.xwxx, #0 - 6: addh h0.x(TRUE), h1.w, -h2.y - 7: texpkb h2.w(TRUE), v5.zwzz, #0 - 9: minh h4.w(TRUE), h2.y, h2 - 10: maxh h5.x(TRUE), h2.y, h2.w - 11: texpkb h0.w(TRUE), v5, #0 - 13: addh h3.w(TRUE), -h0, h0.x - 14: addh h0.x(TRUE), h0.w, h0 - 15: addh h0.z(TRUE), -h2.w, h0.x - 16: addh h0.x(TRUE), h2.w, h3.w - 17: minh h5.y(TRUE), h0.w, h1.w - 18: nrmh h2.xz(TRUE), h0_n - 19: minh_m8 h2.w(TRUE), |h2.x|, |h2.z| - 20: divx h4.xy(TRUE), h2_n.xzzw, h2_n.w - 21: movr r1.zw(TRUE), v4.xxxy - 22: maxh h2.w(TRUE), h0, h1 - 23: fenct TRUE - 24: madr r0.xy(TRUE), -h2.xzzw, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).zwzz, r1.zwzz - 26: texpkb h0(TRUE), r0, #0 - 28: maxh h5.x(TRUE), h2.w, h5 - 29: minh h5.w(TRUE), h5.y, h4 - 30: madr r1.xy(TRUE), h2.xzzw, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).zwzz, r1.zwzz - 32: texpkb h2(TRUE), r1, #0 - 34: addh_d2 h2(TRUE), h0, h2 - 35: texpkb h1(TRUE), v4, #0 - 37: maxh h5.y(TRUE), h5.x, h1.w - 38: minh h4.w(TRUE), h1, h5 - 39: madr r0.xy(TRUE), -h4, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).xyxx, r1.zwzz - 41: texpkb h0(TRUE), r0, #0 - 43: addh_m8 h5.z(TRUE), h5.y, -h4.w - 44: madr r2.xy(TRUE), h4, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).xyxx, r1.zwzz - 46: texpkb h3(TRUE), r2, #0 - 48: addh_d2 h0(TRUE), h0, h3 - 49: addh_d2 h3(TRUE), h0, h2 - 50: movh h0(TRUE), h3 - 51: slth h3.x(TRUE), h3.w, h5.w - 52: sgth h3.w(TRUE), h3, h5.x - 53: addx.c0 rc(TRUE), h3.x, h3 - 54: slth.c0 rc(TRUE), h5.z, h5 - 55: movh h0(c0.NE.w), h2 - 56: movh h0(c0.NE.x), h1 - -IPU0 ------ Simplified schedule: -------- -Pass | Unit | uOp | PC: Op ------+--------+------+------------------------- - 1 | SCT0/1 | mov | 0: TXLr h0.w, g[TEX1].zyxx, const.xxxx, TEX0; - | TEX | txl | 0: TXLr h0.w, g[TEX1].zyxx, const.xxxx, TEX0; - | SCB0 | add | 2: ADDh h2.y, h0.-w--, const.-x--; - | | | - 2 | SCT0/1 | mov | 4: TXLr h1.w, g[TEX1].xwxx, const.xxxx, TEX0; - | TEX | txl | 4: TXLr h1.w, g[TEX1].xwxx, const.xxxx, TEX0; - | SCB0 | add | 6: ADDh h0.x, h1.w---,-h2.y---; - | | | - 3 | SCT0/1 | mov | 7: TXLr h2.w, g[TEX1].zwzz, const.xxxx, TEX0; - | TEX | txl | 7: TXLr h2.w, g[TEX1].zwzz, const.xxxx, TEX0; - | SCB0 | max | 10: MAXh h5.x, h2.y---, h2.w---; - | SCB1 | min | 9: MINh h4.w, h2.---y, h2; - | | | - 4 | SCT0/1 | mov | 11: TXLr h0.w, g[TEX1], const.xxxx, TEX0; - | TEX | txl | 11: TXLr h0.w, g[TEX1], const.xxxx, TEX0; - | SCB0 | add | 14: ADDh h0.x, h0.w---, h0; - | SCB1 | add | 13: ADDh h3.w,-h0, h0.---x; - | | | - 5 | SCT0 | mad | 16: ADDh h0.x, h2.w---, h3.w---; - | SCT1 | mad | 15: ADDh h0.z,-h2.--w-, h0.--x-; - | SCB0 | min | 17: MINh h5.y, h0.-w--, h1.-w--; - | | | - 6 | SCT1 | mov | 18: NRMh h2.xz, h0; - | SRB | nrm | 18: NRMh h2.xz, h0; - | SCB1 | min | 19: MINh*8 h2.w, |h2.---x|, |h2.---z|; - | | | - 7 | SCT0 | div | 20: DIVx h4.xy, h2.xz--, h2.ww--; - | SCT1 | mov | 21: MOVr r1.zw, g[TEX0].--xy; - | SCB1 | max | 22: MAXh h2.w, h0, h1; - | | | - 8 | SCT0 | mad | 24: MADr r0.xy,-h2.xz--, const.zw--, r1.zw--; - | SCT1 | mov | 26: TXLr h0, r0, const.xxxx, TEX0; - | TEX | txl | 26: TXLr h0, r0, const.xxxx, TEX0; - | SCB0 | max | 28: MAXh h5.x, h2.w---, h5; - | SCB1 | min | 29: MINh h5.w, h5.---y, h4; - | | | - 9 | SCT0 | mad | 30: MADr r1.xy, h2.xz--, const.zw--, r1.zw--; - | SCT1 | mov | 32: TXLr h2, r1, const.xxxx, TEX0; - | TEX | txl | 32: TXLr h2, r1, const.xxxx, TEX0; - | SCB0/1 | add | 34: ADDh/2 h2, h0, h2; - | | | - 10 | SCT0/1 | mov | 35: TXLr h1, g[TEX0], const.xxxx, TEX0; - | TEX | txl | 35: TXLr h1, g[TEX0], const.xxxx, TEX0; - | SCB0 | max | 37: MAXh h5.y, h5.-x--, h1.-w--; - | SCB1 | min | 38: MINh h4.w, h1, h5; - | | | - 11 | SCT0 | mad | 39: MADr r0.xy,-h4, const.xy--, r1.zw--; - | SCT1 | mov | 41: TXLr h0, r0, const.zzzz, TEX0; - | TEX | txl | 41: TXLr h0, r0, const.zzzz, TEX0; - | SCB0 | mad | 44: MADr r2.xy, h4, const.xy--, r1.zw--; - | SCB1 | add | 43: ADDh*8 h5.z, h5.--y-,-h4.--w-; - | | | - 12 | SCT0/1 | mov | 46: TXLr h3, r2, const.xxxx, TEX0; - | TEX | txl | 46: TXLr h3, r2, const.xxxx, TEX0; - | SCB0/1 | add | 48: ADDh/2 h0, h0, h3; - | | | - 13 | SCT0/1 | mad | 49: ADDh/2 h3, h0, h2; - | SCB0/1 | mul | 50: MOVh h0, h3; - | | | - 14 | SCT0 | set | 51: SLTh h3.x, h3.w---, h5.w---; - | SCT1 | set | 52: SGTh h3.w, h3, h5.---x; - | SCB0 | set | 54: SLThc0 rc, h5.z---, h5; - | SCB1 | add | 53: ADDxc0_s rc, h3.---x, h3; - | | | - 15 | SCT0/1 | mul | 55: MOVh h0(NE0.wwww), h2; - | SCB0/1 | mul | 56: MOVh h0(NE0.xxxx), h1; - -Pass SCT TEX SCB - 1: 0% 100% 25% - 2: 0% 100% 25% - 3: 0% 100% 50% - 4: 0% 100% 50% - 5: 50% 0% 25% - 6: 0% 0% 25% - 7: 100% 0% 25% - 8: 0% 100% 50% - 9: 0% 100% 100% - 10: 0% 100% 50% - 11: 0% 100% 75% - 12: 0% 100% 100% - 13: 100% 0% 100% - 14: 50% 0% 50% - 15: 100% 0% 100% - -MEAN: 26% 60% 56% - -Pass SCT0 SCT1 TEX SCB0 SCB1 - 1: 0% 0% 100% 100% 0% - 2: 0% 0% 100% 100% 0% - 3: 0% 0% 100% 100% 100% - 4: 0% 0% 100% 100% 100% - 5: 100% 100% 0% 100% 0% - 6: 0% 0% 0% 0% 100% - 7: 100% 100% 0% 0% 100% - 8: 0% 0% 100% 100% 100% - 9: 0% 0% 100% 100% 100% - 10: 0% 0% 100% 100% 100% - 11: 0% 0% 100% 100% 100% - 12: 0% 0% 100% 100% 100% - 13: 100% 100% 0% 100% 100% - 14: 100% 100% 0% 100% 100% - 15: 100% 100% 0% 100% 100% - -MEAN: 33% 33% 60% 86% 80% -Fragment Performance Setup: Driver RSX Compiler, GPU RSX, Flags 0x5 -Results 15 cycles, 3 r regs, 800,000,000 pixels/s -============================================================================*/ -#if (FXAA_PS3 == 1) && (FXAA_EARLY_EXIT == 1) -/*--------------------------------------------------------------------------*/ -#pragma regcount 7 -#pragma disablepc all -#pragma option O2 -#pragma option OutColorPrec=fp16 -#pragma texformat default RGBA8 -/*==========================================================================*/ -half4 FxaaPixelShader( - // See FXAA Quality FxaaPixelShader() source for docs on Inputs! - FxaaFloat2 pos, - FxaaFloat4 fxaaConsolePosPos, - FxaaTex tex, - FxaaTex fxaaConsole360TexExpBiasNegOne, - FxaaTex fxaaConsole360TexExpBiasNegTwo, - FxaaFloat2 fxaaQualityRcpFrame, - FxaaFloat4 fxaaConsoleRcpFrameOpt, - FxaaFloat4 fxaaConsoleRcpFrameOpt2, - FxaaFloat4 fxaaConsole360RcpFrameOpt2, - FxaaFloat fxaaQualitySubpix, - FxaaFloat fxaaQualityEdgeThreshold, - FxaaFloat fxaaQualityEdgeThresholdMin, - FxaaFloat fxaaConsoleEdgeSharpness, - FxaaFloat fxaaConsoleEdgeThreshold, - FxaaFloat fxaaConsoleEdgeThresholdMin, - FxaaFloat4 fxaaConsole360ConstDir -) { -/*--------------------------------------------------------------------------*/ -// (1) - half4 rgbyNe = h4tex2Dlod(tex, half4(fxaaConsolePosPos.zy, 0, 0)); - #if (FXAA_GREEN_AS_LUMA == 0) - half lumaNe = rgbyNe.w + half(1.0/512.0); - #else - half lumaNe = rgbyNe.y + half(1.0/512.0); - #endif -/*--------------------------------------------------------------------------*/ -// (2) - half4 lumaSw = h4tex2Dlod(tex, half4(fxaaConsolePosPos.xw, 0, 0)); - #if (FXAA_GREEN_AS_LUMA == 0) - half lumaSwNegNe = lumaSw.w - lumaNe; - #else - half lumaSwNegNe = lumaSw.y - lumaNe; - #endif -/*--------------------------------------------------------------------------*/ -// (3) - half4 lumaNw = h4tex2Dlod(tex, half4(fxaaConsolePosPos.xy, 0, 0)); - #if (FXAA_GREEN_AS_LUMA == 0) - half lumaMaxNwSw = max(lumaNw.w, lumaSw.w); - half lumaMinNwSw = min(lumaNw.w, lumaSw.w); - #else - half lumaMaxNwSw = max(lumaNw.y, lumaSw.y); - half lumaMinNwSw = min(lumaNw.y, lumaSw.y); - #endif -/*--------------------------------------------------------------------------*/ -// (4) - half4 lumaSe = h4tex2Dlod(tex, half4(fxaaConsolePosPos.zw, 0, 0)); - #if (FXAA_GREEN_AS_LUMA == 0) - half dirZ = lumaNw.w + lumaSwNegNe; - half dirX = -lumaNw.w + lumaSwNegNe; - #else - half dirZ = lumaNw.y + lumaSwNegNe; - half dirX = -lumaNw.y + lumaSwNegNe; - #endif -/*--------------------------------------------------------------------------*/ -// (5) - half3 dir; - dir.y = 0.0; - #if (FXAA_GREEN_AS_LUMA == 0) - dir.x = lumaSe.w + dirX; - dir.z = -lumaSe.w + dirZ; - half lumaMinNeSe = min(lumaNe, lumaSe.w); - #else - dir.x = lumaSe.y + dirX; - dir.z = -lumaSe.y + dirZ; - half lumaMinNeSe = min(lumaNe, lumaSe.y); - #endif -/*--------------------------------------------------------------------------*/ -// (6) - half4 dir1_pos; - dir1_pos.xy = normalize(dir).xz; - half dirAbsMinTimes8 = min(abs(dir1_pos.x), abs(dir1_pos.y)) * half(FXAA_CONSOLE__PS3_EDGE_SHARPNESS); -/*--------------------------------------------------------------------------*/ -// (7) - half4 dir2_pos; - dir2_pos.xy = clamp(dir1_pos.xy / dirAbsMinTimes8, half(-2.0), half(2.0)); - dir1_pos.zw = pos.xy; - dir2_pos.zw = pos.xy; - #if (FXAA_GREEN_AS_LUMA == 0) - half lumaMaxNeSe = max(lumaNe, lumaSe.w); - #else - half lumaMaxNeSe = max(lumaNe, lumaSe.y); - #endif -/*--------------------------------------------------------------------------*/ -// (8) - half4 temp1N; - temp1N.xy = dir1_pos.zw - dir1_pos.xy * fxaaConsoleRcpFrameOpt.zw; - temp1N = h4tex2Dlod(tex, half4(temp1N.xy, 0.0, 0.0)); - half lumaMax = max(lumaMaxNwSw, lumaMaxNeSe); - half lumaMin = min(lumaMinNwSw, lumaMinNeSe); -/*--------------------------------------------------------------------------*/ -// (9) - half4 rgby1; - rgby1.xy = dir1_pos.zw + dir1_pos.xy * fxaaConsoleRcpFrameOpt.zw; - rgby1 = h4tex2Dlod(tex, half4(rgby1.xy, 0.0, 0.0)); - rgby1 = (temp1N + rgby1) * 0.5; -/*--------------------------------------------------------------------------*/ -// (10) - half4 rgbyM = h4tex2Dlod(tex, half4(pos.xy, 0.0, 0.0)); - #if (FXAA_GREEN_AS_LUMA == 0) - half lumaMaxM = max(lumaMax, rgbyM.w); - half lumaMinM = min(lumaMin, rgbyM.w); - #else - half lumaMaxM = max(lumaMax, rgbyM.y); - half lumaMinM = min(lumaMin, rgbyM.y); - #endif -/*--------------------------------------------------------------------------*/ -// (11) - half4 temp2N; - temp2N.xy = dir2_pos.zw - dir2_pos.xy * fxaaConsoleRcpFrameOpt2.zw; - temp2N = h4tex2Dlod(tex, half4(temp2N.xy, 0.0, 0.0)); - half4 rgby2; - rgby2.xy = dir2_pos.zw + dir2_pos.xy * fxaaConsoleRcpFrameOpt2.zw; - half lumaRangeM = (lumaMaxM - lumaMinM) / FXAA_CONSOLE__PS3_EDGE_THRESHOLD; -/*--------------------------------------------------------------------------*/ -// (12) - rgby2 = h4tex2Dlod(tex, half4(rgby2.xy, 0.0, 0.0)); - rgby2 = (temp2N + rgby2) * 0.5; -/*--------------------------------------------------------------------------*/ -// (13) - rgby2 = (rgby2 + rgby1) * 0.5; -/*--------------------------------------------------------------------------*/ -// (14) - #if (FXAA_GREEN_AS_LUMA == 0) - bool twoTapLt = rgby2.w < lumaMin; - bool twoTapGt = rgby2.w > lumaMax; - #else - bool twoTapLt = rgby2.y < lumaMin; - bool twoTapGt = rgby2.y > lumaMax; - #endif - bool earlyExit = lumaRangeM < lumaMax; - bool twoTap = twoTapLt || twoTapGt; -/*--------------------------------------------------------------------------*/ -// (15) - if(twoTap) rgby2 = rgby1; - if(earlyExit) rgby2 = rgbyM; -/*--------------------------------------------------------------------------*/ - return rgby2; } -/*==========================================================================*/ -#endif - - - - - - - - - - -in vec4 pos; - -uniform sampler2D tex0; -uniform vec2 dt; - -void main() { - qgl_FragColor = FxaaPixelShader( - // - // Use noperspective interpolation here (turn off perspective interpolation). - // {xy} = center of pixel - pos.xy, - // - // Used only for FXAA Console, and not used on the 360 version. - // Use noperspective interpolation here (turn off perspective interpolation). - // {xy__} = upper left of pixel - // {__zw} = lower right of pixel - vec4(0), - // - // Input color texture. - // {rgb_} = color in linear or perceptual color space - // if (FXAA_GREEN_AS_LUMA == 0) - // {___a} = luma in perceptual color space (not linear) - tex0, - // - // Only used on the optimized 360 version of FXAA Console. - // For everything but 360, just use the same input here as for "tex". - // For 360, same texture, just alias with a 2nd sampler. - // This sampler needs to have an exponent bias of -1. - tex0, - // - // Only used on the optimized 360 version of FXAA Console. - // For everything but 360, just use the same input here as for "tex". - // For 360, same texture, just alias with a 3nd sampler. - // This sampler needs to have an exponent bias of -2. - tex0, - // - // Only used on FXAA Quality. - // This must be from a constant/uniform. - // {x_} = 1.0/screenWidthInPixels - // {_y} = 1.0/screenHeightInPixels - dt, - // - // Only used on FXAA Console. - // This must be from a constant/uniform. - // This effects sub-pixel AA quality and inversely sharpness. - // Where N ranges between, - // N = 0.50 (default) - // N = 0.33 (sharper) - // {x___} = -N/screenWidthInPixels - // {_y__} = -N/screenHeightInPixels - // {__z_} = N/screenWidthInPixels - // {___w} = N/screenHeightInPixels - vec4(0), - // - // Only used on FXAA Console. - // Not used on 360, but used on PS3 and PC. - // This must be from a constant/uniform. - // {x___} = -2.0/screenWidthInPixels - // {_y__} = -2.0/screenHeightInPixels - // {__z_} = 2.0/screenWidthInPixels - // {___w} = 2.0/screenHeightInPixels - vec4(0), - // - // Only used on FXAA Console. - // Only used on 360 in place of fxaaConsoleRcpFrameOpt2. - // This must be from a constant/uniform. - // {x___} = 8.0/screenWidthInPixels - // {_y__} = 8.0/screenHeightInPixels - // {__z_} = -4.0/screenWidthInPixels - // {___w} = -4.0/screenHeightInPixels - vec4(0), - // - // Only used on FXAA Quality. - // This used to be the FXAA_QUALITY__SUBPIX define. - // It is here now to allow easier tuning. - // Choose the amount of sub-pixel aliasing removal. - // This can effect sharpness. - // 1.00 - upper limit (softer) - // 0.75 - default amount of filtering - // 0.50 - lower limit (sharper, less sub-pixel aliasing removal) - // 0.25 - almost off - // 0.00 - completely off - 0.75, - // - // Only used on FXAA Quality. - // This used to be the FXAA_QUALITY__EDGE_THRESHOLD define. - // It is here now to allow easier tuning. - // The minimum amount of local contrast required to apply algorithm. - // 0.333 - too little (faster) - // 0.250 - low quality - // 0.166 - default - // 0.125 - high quality - // 0.063 - overkill (slower) - 0.125, - // - // Only used on FXAA Quality. - // This used to be the FXAA_QUALITY__EDGE_THRESHOLD_MIN define. - // It is here now to allow easier tuning. - // Trims the algorithm from processing darks. - // 0.0833 - upper limit (default, the start of visible unfiltered edges) - // 0.0625 - high quality (faster) - // 0.0312 - visible limit (slower) - // Special notes when using FXAA_GREEN_AS_LUMA, - // Likely want to set this to zero. - // As colors that are mostly not-green - // will appear very dark in the green channel! - // Tune by looking at mostly non-green content, - // then start at zero and increase until aliasing is a problem. - 0.0625, - // - // Only used on FXAA Console. - // This used to be the FXAA_CONSOLE__EDGE_SHARPNESS define. - // It is here now to allow easier tuning. - // This does not effect PS3, as this needs to be compiled in. - // Use FXAA_CONSOLE__PS3_EDGE_SHARPNESS for PS3. - // Due to the PS3 being ALU bound, - // there are only three safe values here: 2 and 4 and 8. - // These options use the shaders ability to a free *|/ by 2|4|8. - // For all other platforms can be a non-power of two. - // 8.0 is sharper (default!!!) - // 4.0 is softer - // 2.0 is really soft (good only for vector graphics inputs) - 0., - // - // Only used on FXAA Console. - // This used to be the FXAA_CONSOLE__EDGE_THRESHOLD define. - // It is here now to allow easier tuning. - // This does not effect PS3, as this needs to be compiled in. - // Use FXAA_CONSOLE__PS3_EDGE_THRESHOLD for PS3. - // Due to the PS3 being ALU bound, - // there are only two safe values here: 1/4 and 1/8. - // These options use the shaders ability to a free *|/ by 2|4|8. - // The console setting has a different mapping than the quality setting. - // Other platforms can use other values. - // 0.125 leaves less aliasing, but is softer (default!!!) - // 0.25 leaves more aliasing, and is sharper - 0., - // - // Only used on FXAA Console. - // This used to be the FXAA_CONSOLE__EDGE_THRESHOLD_MIN define. - // It is here now to allow easier tuning. - // Trims the algorithm from processing darks. - // The console setting has a different mapping than the quality setting. - // This only applies when FXAA_EARLY_EXIT is 1. - // This does not apply to PS3, - // PS3 was simplified to avoid more shader instructions. - // 0.06 - faster but more aliasing in darks - // 0.05 - default - // 0.04 - slower and less aliasing in darks - // Special notes when using FXAA_GREEN_AS_LUMA, - // Likely want to set this to zero. - // As colors that are mostly not-green - // will appear very dark in the green channel! - // Tune by looking at mostly non-green content, - // then start at zero and increase until aliasing is a problem. - 0., - // - // Extra constants for 360 FXAA Console only. - // Use zeros or anything else for other platforms. - // These must be in physical constant registers and NOT immedates. - // Immedates will result in compiler un-optimizing. - // {xyzw} = float4(1.0, -1.0, 0.25, -0.25) - vec4(0)); -} diff --git a/qglengine/shaders/fxaa.vert b/qglengine/shaders/fxaa.vert deleted file mode 100644 index 02c3d70..0000000 --- a/qglengine/shaders/fxaa.vert +++ /dev/null @@ -1,11 +0,0 @@ -out vec4 pos; - -const float FXAA_SUBPIX_SHIFT = 1. / 4.; -uniform vec2 dt; - -void main(void) { - qgl_FragTexture = qgl_Texture; - pos.xy = qgl_Texture.xy; - pos.zw = qgl_Texture.xy - (dt * (0.5 + FXAA_SUBPIX_SHIFT)); - gl_Position = qgl_ftransform(); -} diff --git a/qglengine/shaders/selection.glsl b/qglengine/shaders/selection.glsl deleted file mode 100644 index 23909ca..0000000 --- a/qglengine/shaders/selection.glsl +++ /dev/null @@ -1,19 +0,0 @@ -// vert // - -flat out uint id, select; - -void main(void) { - id = qgl_ObjectID; - select = qgl_ObjectSelected; - gl_Position = qgl_ftransform(); -} - - -// frag // - -flat in uint id, select; - -void main(void) { - qgl_FragData[0] = unpackUnorm4x8(id); - qgl_FragData[1] = vec4(select); -} diff --git a/qglengine/shaders/selection_apply.glsl b/qglengine/shaders/selection_apply.glsl deleted file mode 100644 index 5029eba..0000000 --- a/qglengine/shaders/selection_apply.glsl +++ /dev/null @@ -1,25 +0,0 @@ -// vert // - -void main(void) { - qgl_FragTexture = qgl_Texture; - gl_Position = qgl_ftransform(); -} - - -// frag // - -uniform sampler2D fb_out, fb_hover, fb_select; - -void main(void) { - ivec2 tc = ivec2(gl_FragCoord.xy); - vec2 stc = qgl_FragTexture.xy; - vec4 src = texelFetch(fb_out , tc, 0); - vec4 hov = texture(fb_hover , stc); - vec4 sel = texture(fb_select, stc); - src.rgb = clamp(src.rgb, vec3(0), vec3(1)); - src.rgb = mix(src.rgb, sel.rgb, sel.a); - src.rgb = mix(src.rgb, hov.rgb, hov.a * 0.667f); - //src.rgb = src.rgb + (sel.rgb*sel.a); - qgl_FragData[0] = src; - //qgl_FragData[0] = vec4(sel.a); -} diff --git a/qglengine/shaders/selection_frame.glsl b/qglengine/shaders/selection_frame.glsl deleted file mode 100644 index e811faa..0000000 --- a/qglengine/shaders/selection_frame.glsl +++ /dev/null @@ -1,24 +0,0 @@ -// vert // - -void main(void) { - qgl_FragTexture = qgl_Texture; - gl_Position = qgl_ftransform(); -} - - -// frag // - -uniform vec2 dt, size; -uniform float thickness; - -void main(void) { - vec2 frame_size = size / dt; - vec2 pix_pos = qgl_FragTexture * frame_size; - vec2 frame = vec2(1) + step(pix_pos, vec2(thickness)) - step(pix_pos, frame_size - vec2(thickness)); - vec2 line = frame * step(0.5, fract(pix_pos.yx / thickness / 4.)); - float fc = max(frame.x, frame.y); - float fl = max(line.x , line.y ); - fl = mix(1, fl, fc); - qgl_FragColor = vec4(vec3(fl), fc * 0.8 + 0.2); - //qgl_FragColor = vec4(vec3(fl,0),1); -} diff --git a/qglengine/shaders/selection_halo.glsl b/qglengine/shaders/selection_halo.glsl deleted file mode 100644 index f62f74f..0000000 --- a/qglengine/shaders/selection_halo.glsl +++ /dev/null @@ -1,42 +0,0 @@ -// vert // - -void main(void) { - gl_Position = qgl_ftransform(); -} - - -// frag // - -uniform sampler2D fb_hover, fb_selection; -uniform vec4 hover_id, hover_color, selection_color; -uniform float hover_fill, selection_fill, has_hover, has_selection; -ivec2 tc; - -vec4 diffVector(in sampler2D map, in vec4 id) { - vec4 ds0 = abs(texelFetchOffset(map, tc, 0, ivec2(-1, 0)) - id); - vec4 ds1 = abs(texelFetchOffset(map, tc, 0, ivec2( 1, 0)) - id); - vec4 ds2 = abs(texelFetchOffset(map, tc, 0, ivec2(0, -1)) - id); - vec4 ds3 = abs(texelFetchOffset(map, tc, 0, ivec2(0, 1)) - id); - return vec4(dot(ds0, vec4(1)), dot(ds1, vec4(1)), dot(ds2, vec4(1)), dot(ds3, vec4(1))); -} -vec2 diffPair(in vec4 dv) { - const float _c = 64; - return vec2(step(1e-6, dot(dv, vec4(1))), - step(1e-3, (dv.r * _c) * (dv.g * _c) * (dv.b * _c) * (dv.a * _c))); -} -float diffAlpha(in vec2 dp, in float fill) { - return mix(dp.x - dp.y, dp.x - dp.y - dp.y + 1, fill); -} - -void main(void) { - tc = ivec2(gl_FragCoord.xy); - float hh = clamp(dot(hover_id, vec4(1)), 0, 1); - - vec2 dp = diffPair(diffVector(fb_hover, hover_id)); - float v = diffAlpha(dp, hover_fill); - qgl_FragData[0] = has_hover*hh*v*vec4(hover_color.rgb, hover_color.a); - - dp = diffPair(diffVector(fb_selection, vec4(1))); - v = diffAlpha(dp, selection_fill); - qgl_FragData[1] = has_selection*v*vec4(selection_color.rgb, selection_color.a); -} diff --git a/qglengine/shaders/service_fill.glsl b/qglengine/shaders/service_fill.glsl deleted file mode 100644 index bc1cc8f..0000000 --- a/qglengine/shaders/service_fill.glsl +++ /dev/null @@ -1,24 +0,0 @@ -// vert // - -out vec3 geom_normal; -out vec4 object_color; - -void main(void) { - qgl_FragTexture = qgl_Texture; - gl_Position = qgl_ftransform(); - - geom_normal = normalize(qgl_Normal * qgl_getNormalMatrix()); - object_color = qgl_ObjectColor; -} - - -// frag // - -in vec3 geom_normal; -in vec4 object_color; - -void main(void) { - vec3 normal = normalize(geom_normal); - float l = max(0, dot(normal, vec3(0,0,1))); - qgl_FragColor = object_color * (l * 0.6 + 0.4); -} diff --git a/qglengine/shaders/service_frame.glsl b/qglengine/shaders/service_frame.glsl deleted file mode 100644 index 65189c1..0000000 --- a/qglengine/shaders/service_frame.glsl +++ /dev/null @@ -1,51 +0,0 @@ -// vert // - -out vec4 object_color_g; -out float mat_scale; - -void main(void) { - gl_Position = qgl_ftransform(); - object_color_g = qgl_ObjectColor; - //mat_scale = pow(qgl_ModelMatrix[0][0] * qgl_ModelMatrix[1][1] * qgl_ModelMatrix[2][2], 0.3333); - mat_scale = pow(determinant(mat3(qgl_ModelMatrix)), 0.333); - //mat3 mm = transpose(mat3(qgl_ModelMatrix)); - //mat_scale = min(min(dot(vec3(1), mm[0]), dot(vec3(1), mm[1])), dot(vec3(1), mm[2])); -} - - -// geom // - -layout (lines) in; -layout (triangle_strip, max_vertices = 4) out; - -in float mat_scale[]; -in vec4 object_color_g[]; -out vec4 object_color; - -uniform float line_width, z_offset; -uniform mat4 qgl_ProjMatrix; - -void main(void) { - object_color = object_color_g[0]; - vec2 dir = normalize(gl_in[0].gl_Position.xy - gl_in[1].gl_Position.xy); - vec2 side = cross(vec3(dir, 0), vec3(0, 0, 1)).xy; - vec4 vo = vec4(0, 0, z_offset, 0); - float dts = 0.05 * line_width * mat_scale[0]; - dir *= dts; - side *= dts; - gl_Position = gl_in[0].gl_Position + vec4((dir + side), 0, 0)*qgl_ProjMatrix + vo; EmitVertex(); - gl_Position = gl_in[0].gl_Position + vec4((dir - side), 0, 0)*qgl_ProjMatrix + vo; EmitVertex(); - gl_Position = gl_in[1].gl_Position - vec4((dir - side), 0, 0)*qgl_ProjMatrix + vo; EmitVertex(); - gl_Position = gl_in[1].gl_Position - vec4((dir + side), 0, 0)*qgl_ProjMatrix + vo; EmitVertex(); - EndPrimitive(); -} - - -// frag // - -in vec4 object_color; -uniform float scale; - -void main(void) { - qgl_FragColor = object_color; -} diff --git a/qglengine/shaders/service_line.glsl b/qglengine/shaders/service_line.glsl deleted file mode 100644 index 2cfec5d..0000000 --- a/qglengine/shaders/service_line.glsl +++ /dev/null @@ -1,17 +0,0 @@ -// vert // - -out vec4 object_color; - -void main(void) { - gl_Position = qgl_ftransform(); - object_color = qgl_ObjectColor; -} - - -// frag // - -in vec4 object_color; - -void main(void) { - qgl_FragColor = object_color; -} diff --git a/qglengine/shaders/sum.glsl b/qglengine/shaders/sum.glsl deleted file mode 100644 index e12fd95..0000000 --- a/qglengine/shaders/sum.glsl +++ /dev/null @@ -1,25 +0,0 @@ -// vert // - -layout(location = 1) in ivec2 qgl_Vertex; - -flat out vec4 color; - -uniform sampler2D tex; - -void main(void) { - color = texelFetch(tex, qgl_Vertex, 0); - gl_Position = vec4(0,0,0,1); -} - - -// frag // - -out vec4 qgl_FragData[gl_MaxDrawBuffers]; - -flat in vec4 color; - -uniform float pcnt; - -void main(void) { - qgl_FragData[0] = color;// / pcnt; -} diff --git a/qglengine/tonemapping_proc.cpp b/qglengine/tonemapping_proc.cpp deleted file mode 100644 index b12b67c..0000000 --- a/qglengine/tonemapping_proc.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/* - QGL TonemappingProc - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#define GL_GLEXT_PROTOTYPES -#include -#include "tonemapping_proc.h" -#include "qglview.h" -#include - -using namespace QGLEngineShaders; - - -TonemappingProc::TonemappingProc(Renderer * rend): QThread(), r(rend), - fbo_1x1(r->view, 1, false, GL_RGB32F), - fbomm(r->fbo_out, Renderer::obrSum, 3), - buffer_vbo(GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW) { - shader_sum = 0; - timer_delim = 0; - frame_max = cur_max = 1.; - need_render_sum = exit_ = false; - enabled = false; - timer_tone = startTimer(10); -} - - -TonemappingProc::~TonemappingProc() { - exit_ = true; - if (!wait(1000)) - terminate(); - killTimer(timer_tone); - if (shader_sum) delete shader_sum; -} - - -void TonemappingProc::init() { - QOpenGLExtraFunctions * f = r->view; - buffer_vbo.init(f); - f->glGenVertexArrays(1, &vbo_vao); - f->glBindVertexArray(vbo_vao); - buffer_vbo.bind(f); - f->glEnableVertexAttribArray(1); - f->glVertexAttribIPointer(1, 2, GL_UNSIGNED_INT, 0, 0); - buffer_vbo.release(f); - f->glBindVertexArray(0); - fbomm.lastPlane().enablePixelBuffer(); - fbo_1x1.resize(1, 1); - resize(); - if (!isRunning()) start(); -} - - -void TonemappingProc::resize() { - QOpenGLExtraFunctions * f = r->view; - fbomm.resize(); - int pcnt = fbomm.width(fbomm.lastLevel()) * fbomm.height(fbomm.lastLevel()); - QVector _data; - _data.resize(pcnt); - pcnt = -1; - for (int x = 0; x < fbomm.width(fbomm.lastLevel()); ++x) - for (int y = 0; y < fbomm.height(fbomm.lastLevel()); ++y) - _data[++pcnt] = Vector2i(x,y); - buffer_vbo.bind(f); - buffer_vbo.resize(f, _data.size() * sizeof(Vector2i)); - buffer_vbo.load(f, _data.constData(), _data.size() * sizeof(Vector2i)); -} - - -void TonemappingProc::timerEvent(QTimerEvent * e) { - if (!fbo_1x1.isInit() || !enabled) return; - if (timer_delim == 0) - need_render_sum = true; - timer_delim = (timer_delim + 1) % 10; - mutex.lock(); - float fmax = frame_max; - mutex.unlock(); - float dt = 0.01f, a = dt * 5.f, b = 1.f - a; - cur_max = fmax * a + cur_max * b; -} - - -void TonemappingProc::renderSum(Framebuffer & fbo_src, int index) { - QOpenGLExtraFunctions * f = r->view; - int pcnt = fbo_src.width() * fbo_src.height(); - fbo_src.bindColorTexture(index); - fbo_1x1.bind(); - //glClearFramebuffer(Qt::white, false); - glClearFramebuffer(); - if (shader_sum) { - if (shader_sum->isLinked()) { - if (shader_sum->bind()) { - shader_sum->setUniformValue("tex", 0); - shader_sum->setUniformValue("pcnt", float(pcnt)); - f->glBindVertexArray(vbo_vao); - f->glEnable(GL_BLEND); - f->glBlendFunc(GL_ONE, GL_ONE); - f->glBlendEquation(GL_MAX); - f->glDrawArrays(GL_POINTS, 0, pcnt); - f->glBlendEquation(GL_FUNC_ADD); - f->glDisable(GL_BLEND); - f->glBindVertexArray(0); - } - } - } - fbo_1x1.release(); - //fbo_src.bind(); -} - - -void TonemappingProc::run() { - while (!exit_) { - if (!enabled) { - msleep(100); - continue; - } - mutex.lock(); - if (last_data.isEmpty()) { - mutex.unlock(); - msleep(10); - continue; - } - QVector data = last_data; - last_data.clear(); - mutex.unlock(); - float max = calcHistogram(data); - last_max << max; - if (last_max.size() > 5) - last_max.removeAt(0); - float cm = last_max[0]; - for (int i = 1; i < last_max.size(); ++i) - cm += last_max[i]; - cm /= last_max.size(); - mutex.lock(); - frame_max = cm; - mutex.unlock(); - } -} - - -float TonemappingProc::calcHistogram(const QVector & data) { - if (data.isEmpty()) return 1.f; - float max = 0.; - QVector3D luma(0.299, 0.587, 0.114); - foreach (const QVector4D & p, data) { - float l = QVector3D::dotProduct(p.toVector3D(), luma); - max = qMax(max, l); - } - return max; -} - - -bool TonemappingProc::process() { - if (!need_render_sum || !enabled) return false; - need_render_sum = false; - Framebuffer & fbo(fbomm.lastPlane()); - if (fbo.queriedPoints() > 0) { - QVector data = fbo.getPointsFloat(); - mutex.lock(); - last_data = data; - mutex.unlock(); - } - fbomm.create(); - fbo.queryPoints(0, fbo.rect(), GL_FLOAT); - //renderSum(fbomm.plane(fbomm.lastLevel()), 0); - return true; -} - - -float TonemappingProc::frameMax() { - if (!enabled) return 1.f; - return cur_max; -} diff --git a/qglengine/tonemapping_proc.h b/qglengine/tonemapping_proc.h deleted file mode 100644 index b6f99d5..0000000 --- a/qglengine/tonemapping_proc.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - QGL TonemappingProc - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef TONEMAPPING_PROC_H -#define TONEMAPPING_PROC_H - -#include "glframebuffer_mipmap.h" -#include - - -class TonemappingProc: public QThread -{ - friend class Renderer; - friend class QGLView; -public: - TonemappingProc(Renderer * rend); - virtual ~TonemappingProc(); - - void init(); - void resize(); - void prepareSum(); - void renderSum(Framebuffer & fbo_src, int index); - - bool process(); - float frameMax(); - -protected: - void timerEvent(QTimerEvent * e); - void run() override; - float calcHistogram(const QVector & data); - -private: - Renderer * r; - QMutex mutex; - QVector last_data; - QVector last_max; - - float frame_max, cur_max; - bool need_render_sum, enabled; - std::atomic_bool exit_; - int timer_tone, timer_delim; - Framebuffer fbo_1x1; - FramebufferMipmap fbomm; - - QOpenGLShaderProgram * shader_sum; - Buffer buffer_vbo; - GLenum vbo_vao; - -}; - -#endif // RENDERER_H diff --git a/qglengine/widgets/CMakeLists.txt b/qglengine/widgets/CMakeLists.txt deleted file mode 100644 index 31b3b2e..0000000 --- a/qglengine/widgets/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -project(qglengine_widgets) -if (POLICY CMP0017) - cmake_policy(SET CMP0017 NEW) -endif() -find_qt(Qt5 Core Gui Widgets) -qt_sources(SRC) -qt_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM) -file(GLOB PHS "*_p.h") -list(REMOVE_ITEM out_HDR "${PHS}") -import_version(${PROJECT_NAME} qglengine) -set_deploy_property(${PROJECT_NAME} SHARED - LABEL "QGLEngine widgets library" - FULLNAME "${_DOMAIN}.${PROJECT_NAME}" - COMPANY "${_COMPANY}" - INFO "QGLEngine widgets library") -make_rc(${PROJECT_NAME} _RC) -qt_add_library(${PROJECT_NAME} SHARED out_CPP ${_RC}) -qt_generate_export_header(${PROJECT_NAME}) -list(APPEND out_HDR "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_export.h") -qt_target_link_libraries(${PROJECT_NAME} qad_utils qad_widgets qglengine_core) -qt_target_include_directories(${PROJECT_NAME} PRIVATE ${QAD_INCLUDES} "${CMAKE_CURRENT_SOURCE_DIR}/../" "${CMAKE_CURRENT_SOURCE_DIR}/../core") -list(APPEND QT_MULTILIB_LIST ${PROJECT_NAME}) -copy_to_parent("") -#message(STATUS "Building ${PROJECT_NAME}") -sdk_install("qglengine" FALSE "${PROJECT_NAME}" "${out_HDR}" "${out_QM}") diff --git a/qglengine/widgets/material_editor.cpp b/qglengine/widgets/material_editor.cpp deleted file mode 100644 index e6636fe..0000000 --- a/qglengine/widgets/material_editor.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/* - QGL MaterialEditor - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "material_editor.h" -#include "ui_material_editor.h" -#include "glmaterial.h" - - -MaterialEditor::MaterialEditor(QWidget * parent): QWidget(parent) { - ui = new Ui::MaterialEditor(); - ui->setupUi(this); - ui->mapDiffuse ->configure(tr("Diffuse"), true); - ui->mapNormal ->configure(tr("Normal")); - ui->mapMetalness->configure(tr("Metalness")); - ui->mapRoughness->configure(tr("Roughness")); - ui->mapEmission ->configure(tr("Emission"), true); - ui->mapRelief ->configure(tr("Relief")); - ui->checkGlass->hide(); - ui->frameReflection->hide(); - ui->label_13->hide(); - mat = 0; - active = true; - ignore_next = 0; -} - - -void MaterialEditor::changeEvent(QEvent * e) { - QWidget::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - ui->retranslateUi(this); - break; - default: - break; - } -} - - -void MaterialEditor::materialChanged() { - if (!active || !mat) return; - ignore_next = 2; - mat->_changed = true; - mat->color_diffuse = ui->mapDiffuse ->color(); - mat->color_emission = ui->mapEmission->color(); - mat->transparency = ui->spinTransparent->value(); - mat->reflectivity = ui->spinReflect->value(); - mat->iof = ui->spinIOF->value(); - mat->dispersion = ui->spinDispersion->value(); - mat->glass = ui->checkGlass->isChecked(); - //emit changed(); -} - - -void MaterialEditor::setMaterial(Material * m) { - if (ignore_next > 0) { - //ignore_next = false; - return; - } - active = false; - mat = m; - setEnabled(m); - if (!mat) return; - ui->mapDiffuse ->setColor(mat->color_diffuse ); - ui->mapEmission->setColor(mat->color_emission); - ui->spinTransparent->setValue(mat->transparency); - ui->spinReflect->setValue(mat->reflectivity); - ui->spinIOF->setValue(mat->iof); - ui->spinDispersion->setValue(mat->dispersion); - ui->checkGlass->setChecked(mat->glass); - ui->mapDiffuse ->setMap(&(mat->map_diffuse )); - ui->mapNormal ->setMap(&(mat->map_normal )); - ui->mapMetalness->setMap(&(mat->map_metalness)); - ui->mapRoughness->setMap(&(mat->map_roughness)); - ui->mapEmission ->setMap(&(mat->map_emission )); - ui->mapRelief ->setMap(&(mat->map_relief )); - /*ui->lineReflFront->setProperty("GLpath", mat->map_reflection.path(0)); ui->lineReflFront->setText(QFileInfo(mat->map_reflection.path(0)).fileName()); - ui->lineReflBack->setProperty("GLpath", mat->map_reflection.path(1)); ui->lineReflBack->setText(QFileInfo(mat->map_reflection.path(1)).fileName()); - ui->lineReflLeft->setProperty("GLpath", mat->map_reflection.path(2)); ui->lineReflLeft->setText(QFileInfo(mat->map_reflection.path(2)).fileName()); - ui->lineReflRight->setProperty("GLpath", mat->map_reflection.path(3)); ui->lineReflRight->setText(QFileInfo(mat->map_reflection.path(3)).fileName()); - ui->lineReflTop->setProperty("GLpath", mat->map_reflection.path(4)); ui->lineReflTop->setText(QFileInfo(mat->map_reflection.path(4)).fileName()); - ui->lineReflBottom->setProperty("GLpath", mat->map_reflection.path(5)); ui->lineReflBottom->setText(QFileInfo(mat->map_reflection.path(5)).fileName()); - */active = true; -} - -/* -Material MaterialEditor::material() { - Material m; - mat->color_diffuse = ui->colorDiffuse ->color(); - mat->color_specular = ui->colorSpecular->color(); - mat->color_emission = ui->colorEmission->color(); - mat->transparency = ui->spinTransparent->value(); - mat->reflectivity = ui->spinReflect->value(); - mat->iof = ui->spinIOF->value(); - mat->dispersion = ui->spinDispersion->value(); - mat->glass = ui->checkGlass->isChecked(); - mat->map_diffuse = ui->mapDiffuse->map(); - mat->map_normal = ui->mapNormal->map(); - mat->map_specular = ui->mapSpecular->map(); - mat->map_roughness = ui->mapRoughness->map(); - mat->map_emission = ui->mapEmission->map(); - mat->map_relief = ui->mapRelief->map(); - mat->map_reflection.setPath(0, ui->lineReflFront->property("GLpath").toString()); - mat->map_reflection.setPath(1, ui->lineReflBack->property("GLpath").toString()); - mat->map_reflection.setPath(2, ui->lineReflLeft->property("GLpath").toString()); - mat->map_reflection.setPath(3, ui->lineReflRight->property("GLpath").toString()); - mat->map_reflection.setPath(4, ui->lineReflTop->property("GLpath").toString()); - mat->map_reflection.setPath(5, ui->lineReflBottom->property("GLpath").toString()); - return m; -} -*/ - -void MaterialEditor::on_buttonReflFrontSelect_clicked() { - QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflFront->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); - if (str.isEmpty()) return; - ui->lineReflFront->setProperty("GLpath", str); - ui->lineReflFront->setText(QFileInfo(str).fileName()); - materialChanged(); -} - - -void MaterialEditor::on_buttonReflBackSelect_clicked() { - QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflBack->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); - if (str.isEmpty()) return; - ui->lineReflBack->setProperty("GLpath", str); - ui->lineReflBack->setText(QFileInfo(str).fileName()); - materialChanged(); -} - - -void MaterialEditor::on_buttonReflLeftSelect_clicked() { - QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflLeft->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); - if (str.isEmpty()) return; - ui->lineReflLeft->setProperty("GLpath", str); - ui->lineReflLeft->setText(QFileInfo(str).fileName()); - materialChanged(); -} - - -void MaterialEditor::on_buttonReflRightSelect_clicked() { - QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflRight->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); - if (str.isEmpty()) return; - ui->lineReflRight->setProperty("GLpath", str); - ui->lineReflRight->setText(QFileInfo(str).fileName()); - materialChanged(); -} - - -void MaterialEditor::on_buttonReflTopSelect_clicked() { - QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflTop->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); - if (str.isEmpty()) return; - ui->lineReflTop->setProperty("GLpath", str); - ui->lineReflTop->setText(QFileInfo(str).fileName()); - materialChanged(); -} - - -void MaterialEditor::on_buttonReflBottomSelect_clicked() { - QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflBottom->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); - if (str.isEmpty()) return; - ui->lineReflBottom->setProperty("GLpath", str); - ui->lineReflBottom->setText(QFileInfo(str).fileName()); - materialChanged(); -} - - -void MaterialEditor::on_buttonReflFrontClear_clicked() { - ui->lineReflFront->setText(""); - ui->lineReflFront->setProperty("GLpath", ""); - materialChanged(); -} - - -void MaterialEditor::on_buttonReflBackClear_clicked() { - ui->lineReflBack->setText(""); - ui->lineReflBack->setProperty("GLpath", ""); - materialChanged(); -} - - -void MaterialEditor::on_buttonReflLeftClear_clicked() { - ui->lineReflLeft->setText(""); - ui->lineReflLeft->setProperty("GLpath", ""); - materialChanged(); -} - - -void MaterialEditor::on_buttonReflRightClear_clicked() { - ui->lineReflRight->setText(""); - ui->lineReflRight->setProperty("GLpath", ""); - materialChanged(); -} - - -void MaterialEditor::on_buttonReflTopClear_clicked() { - ui->lineReflTop->setText(""); - ui->lineReflTop->setProperty("GLpath", ""); - materialChanged(); -} - - -void MaterialEditor::on_buttonReflBottomClear_clicked() { - ui->lineReflBottom->setText(""); - ui->lineReflBottom->setProperty("GLpath", ""); - materialChanged(); -} - - -void MaterialEditor::on_buttonLoadCubeDir_clicked() { - QString dir = QFileDialog::getExistingDirectory(this, "Select directory", ui->lineReflFront->property("GLpath").toString()); - if (dir.isEmpty()) return; - /*CubeTexture cb(0); - cb.loadPathesFromDirectory(dir); - active = false; - ui->lineReflFront->setProperty("GLpath", cb.path(0)); ui->lineReflFront->setText(QFileInfo(cb.path(0)).fileName()); - ui->lineReflBack->setProperty("GLpath", cb.path(1)); ui->lineReflBack->setText(QFileInfo(cb.path(1)).fileName()); - ui->lineReflLeft->setProperty("GLpath", cb.path(2)); ui->lineReflLeft->setText(QFileInfo(cb.path(2)).fileName()); - ui->lineReflRight->setProperty("GLpath", cb.path(3)); ui->lineReflRight->setText(QFileInfo(cb.path(3)).fileName()); - ui->lineReflTop->setProperty("GLpath", cb.path(4)); ui->lineReflTop->setText(QFileInfo(cb.path(4)).fileName()); - ui->lineReflBottom->setProperty("GLpath", cb.path(5)); ui->lineReflBottom->setText(QFileInfo(cb.path(5)).fileName());*/ - active = true; - materialChanged(); -} diff --git a/qglengine/widgets/material_editor.h b/qglengine/widgets/material_editor.h deleted file mode 100644 index 16bc29d..0000000 --- a/qglengine/widgets/material_editor.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - QGL MaterialEditor - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef MATERIAL_EDITOR_H -#define MATERIAL_EDITOR_H - -#include -#include "gltypes.h" - -namespace Ui { - class MaterialEditor; -} - -class MaterialEditor: public QWidget -{ - friend class MaterialsEditor; - Q_OBJECT -public: - explicit MaterialEditor(QWidget * parent = 0); - - void setMaterial(Material * m); - -protected: - void changeEvent(QEvent * e); - - bool active; - int ignore_next; - Ui::MaterialEditor * ui; - Material * mat; - -private slots: - void materialChanged(); - void on_buttonReflFrontSelect_clicked(); - void on_buttonReflFrontClear_clicked(); - void on_buttonReflBackSelect_clicked(); - void on_buttonReflBackClear_clicked(); - void on_buttonReflLeftSelect_clicked(); - void on_buttonReflLeftClear_clicked(); - void on_buttonReflRightSelect_clicked(); - void on_buttonReflRightClear_clicked(); - void on_buttonReflTopSelect_clicked(); - void on_buttonReflTopClear_clicked(); - void on_buttonReflBottomSelect_clicked(); - void on_buttonReflBottomClear_clicked(); - void on_buttonLoadCubeDir_clicked(); - -signals: - void changed(); - -}; - -#endif // MATERIAL_EDITOR_H diff --git a/qglengine/widgets/material_editor.ui b/qglengine/widgets/material_editor.ui deleted file mode 100644 index 307d6a7..0000000 --- a/qglengine/widgets/material_editor.ui +++ /dev/null @@ -1,637 +0,0 @@ - - - MaterialEditor - - - - 0 - 0 - 435 - 535 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - font:normal; - - - - - - - Qt::Horizontal - - - - - - - font:normal; - - - - - - - Qt::Horizontal - - - - - - - font:normal; - - - - - - - Qt::Horizontal - - - - - - - font:normal; - - - - - - - Qt::Horizontal - - - - - - - font:normal; - - - - - - - Qt::Horizontal - - - - - - - font:normal; - - - - - - - Qt::Horizontal - - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - Glass - - - - - - - Transparency - - - - - - - 1.000000000000000 - - - 2 - - - 0.010000000000000 - - - 0.100000000000000 - - - - - - - Reflectivity - - - - - - - 1.000000000000000 - - - 2 - - - 0.010000000000000 - - - 0.100000000000000 - - - - - - - IOF - - - - - - - 2.000000000000000 - - - 1.000000000000000 - - - 2 - - - 0.010000000000000 - - - 0.100000000000000 - - - - - - - Dispersion - - - - - - - 1.000000000000000 - - - 0.100000000000000 - - - 2 - - - 0.010000000000000 - - - 0.100000000000000 - - - - - - - Reflection map - - - - - - - QFrame::StyledPanel - - - QFrame::Sunken - - - - - - Front: - - - - - - - Back: - - - - - - - Left: - - - - - - - Right: - - - - - - - Top: - - - - - - - Bottom: - - - - - - - 2 - - - - - - - - X - - - - - - - ^ - - - - - - - - - 2 - - - - - - - - X - - - - - - - ^ - - - - - - - - - 2 - - - - - - - - X - - - - - - - ^ - - - - - - - - - 2 - - - - - - - - X - - - - - - - ^ - - - - - - - - - 2 - - - - - - - - X - - - - - - - ^ - - - - - - - - - 2 - - - - - - - - X - - - - - - - ^ - - - - - - - - - load from directory - - - - - - - - - - - - - SpinSlider - QWidget -
spinslider.h
-
- - MaterialMapEditor - QWidget -
material_map_editor.h
- 1 - - changed() - -
-
- - - - spinTransparent - valueChanged(double) - MaterialEditor - materialChanged() - - - 433 - 468 - - - 283 - 149 - - - - - spinReflect - valueChanged(double) - MaterialEditor - materialChanged() - - - 433 - 497 - - - 284 - 174 - - - - - spinIOF - valueChanged(double) - MaterialEditor - materialChanged() - - - 433 - 526 - - - 284 - 236 - - - - - checkGlass - toggled(bool) - MaterialEditor - materialChanged() - - - 433 - 439 - - - 284 - 84 - - - - - spinDispersion - valueChanged(double) - MaterialEditor - materialChanged() - - - 433 - 555 - - - 326 - 288 - - - - - mapDiffuse - changed() - MaterialEditor - materialChanged() - - - 421 - 69 - - - 434 - 63 - - - - - mapMetalness - changed() - MaterialEditor - materialChanged() - - - 421 - 189 - - - 434 - 143 - - - - - mapEmission - changed() - MaterialEditor - materialChanged() - - - 421 - 338 - - - 434 - 216 - - - - - mapNormal - changed() - MaterialEditor - materialChanged() - - - 421 - 129 - - - 434 - 260 - - - - - mapRelief - changed() - MaterialEditor - materialChanged() - - - 421 - 398 - - - 434 - 304 - - - - - mapRoughness - changed() - MaterialEditor - materialChanged() - - - 421 - 249 - - - 434 - 250 - - - - - - materialChanged() - -
diff --git a/qglengine/widgets/material_map_editor.cpp b/qglengine/widgets/material_map_editor.cpp deleted file mode 100644 index 3768d82..0000000 --- a/qglengine/widgets/material_map_editor.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - QGL MaterialMapEditor - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "material_map_editor.h" -#include "ui_material_map_editor.h" -#include "gltexture_manager.h" -#include "glmaterial.h" - - -MaterialMapEditor::MaterialMapEditor(QWidget * parent): QWidget(parent) { - ui = new Ui::MaterialMapEditor(); - ui->setupUi(this); - ui->widgetMap->hide(); - active = true; -} - - -void MaterialMapEditor::changeEvent(QEvent * e) { - QWidget::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - ui->retranslateUi(this); - break; - default: - break; - } -} - - -void MaterialMapEditor::resizeEvent(QResizeEvent * e) { - QSize sz = preferredIconSize(6, this); - ui->iconedLabel->setFixedSize(sz); - ui->iconedLabel->setIconSize(sz); -} - - -void MaterialMapEditor::updateIcon() { - ui->iconedLabel->setIcon(QIcon(TextureManager::findFile(ui->linePath->property("GLpath").toString()))); -} - - -void MaterialMapEditor::mapChanged() { - if (!active || !map) return; - active = false; - map->use_bitmap = ui->checkMap->isChecked(); - if (ui->checkMap->isChecked()) { - map->color_amount = ui->sliderAmount->value(); - map->color_offset = ui->sliderOffset->value(); - } else { - map->color_amount = ui->sliderValue->value(); - map->color_offset = 0.f; - } - map->bitmap_scale.setX(ui->spinScaleX->value()); - map->bitmap_scale.setY(ui->spinScaleY->value()); - active = true; - emit changed(); -} - - -void MaterialMapEditor::setMap(Map * m) { - active = false; - map = m; - setEnabled(m); - if (!map) return; - ui->stackedWidget->setCurrentIndex(map->use_bitmap ? 1 : 0); - ui->checkMap->setChecked(map->use_bitmap); - ui->sliderValue->setValue(map->color_amount); - ui->sliderAmount->setValue(map->color_amount); - ui->sliderOffset->setValue(map->color_offset); - ui->spinScaleX->setValue(map->bitmap_scale.x()); - ui->spinScaleY->setValue(map->bitmap_scale.y()); - ui->linePath->setProperty("GLpath", map->bitmap_path); ui->linePath->setText(QFileInfo(map->bitmap_path).fileName()); - updateIcon(); - active = true; -} - - -void MaterialMapEditor::configure(QString title, bool has_color) { - ui->labelTitle->setText(title); - ui->colorButton->setVisible(has_color); -} - - -void MaterialMapEditor::setColor(QColor c) { - active = false; - ui->colorButton->setColor(c); - active = true; -} - - -QColor MaterialMapEditor::color() const { - return ui->colorButton->color(); -} - -/* -Map MaterialMapEditor::map() { - Map m; - map->color_amount = ui->sliderAmount->value(); - map->color_offset = ui->sliderOffset->value(); - map->bitmap_scale.setX(ui->spinScaleX->value()); - map->bitmap_scale.setY(ui->spinScaleY->value()); - map->bitmap_path = ui->linePath->property("GLpath").toString(); - return m; -} -*/ - -void MaterialMapEditor::on_buttonSelect_clicked() { - QString str = QFileDialog::getOpenFileName(this, "Select image", ui->linePath->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); - if (str.isEmpty()) return; - ui->linePath->setProperty("GLpath", str); - ui->linePath->setText(QFileInfo(str).fileName()); - map->setBitmapPath(str); - updateIcon(); - mapChanged(); -} - - -void MaterialMapEditor::on_buttonClear_clicked() { - ui->linePath->setText(""); - ui->linePath->setProperty("GLpath", ""); - map->clearBitmap(); - updateIcon(); - mapChanged(); -} - - -void MaterialMapEditor::on_checkMap_toggled(bool checked) { - if (checked) { - ui->sliderAmount->setValue(ui->sliderValue->value()); - resizeEvent(0); - } else - ui->sliderValue->setValue(ui->sliderAmount->value()); - ui->stackedWidget->setCurrentIndex(checked ? 1 : 0); - mapChanged(); -} diff --git a/qglengine/widgets/material_map_editor.h b/qglengine/widgets/material_map_editor.h deleted file mode 100644 index 8175247..0000000 --- a/qglengine/widgets/material_map_editor.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - QGL MaterialMapEditor - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef MATERIAL_MAP_EDITOR_H -#define MATERIAL_MAP_EDITOR_H - -#include -#include "gltypes.h" - -namespace Ui { - class MaterialMapEditor; -} - -class MaterialMapEditor: public QWidget -{ - Q_OBJECT -public: - explicit MaterialMapEditor(QWidget * parent = 0); - - void setMap(Map * m); - void configure(QString title, bool has_color = false); - void setColor(QColor c); - QColor color() const; - -protected: - void changeEvent(QEvent * e); - void resizeEvent(QResizeEvent * e); - void updateIcon(); - - bool active; - Ui::MaterialMapEditor * ui; - Map * map; - -private slots: - void mapChanged(); - void on_buttonSelect_clicked(); - void on_buttonClear_clicked(); - void on_checkMap_toggled(bool checked); - -signals: - void changed(); - -}; - -#endif // MATERIAL_MAP_EDITOR_H diff --git a/qglengine/widgets/material_map_editor.ui b/qglengine/widgets/material_map_editor.ui deleted file mode 100644 index 33ca383..0000000 --- a/qglengine/widgets/material_map_editor.ui +++ /dev/null @@ -1,506 +0,0 @@ - - - MaterialMapEditor - - - - 0 - 0 - 725 - 218 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - 0 - 0 - - - - font: bold; - - - title: - - - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0.000000000000000 - - - 1.000000000000000 - - - 1.000000000000000 - - - 2 - - - 0.050000000000000 - - - 0.200000000000000 - - - 0.000000000000000 - - - 1.000000000000000 - - - - - - - - - - - - - 0 - 0 - - - - Map - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - IconedLabel::RightToLeft - - - - - - - - - 2 - - - - - - - - - :/icons/edit-delete.png:/icons/edit-delete.png - - - - - - - - :/icons/document-open.png:/icons/document-open.png - - - - - - - - - Amount: - - - - - - - -1.000000000000000 - - - 1.000000000000000 - - - 1.000000000000000 - - - 2 - - - 0.050000000000000 - - - 0.200000000000000 - - - -99.000000000000000 - - - 99.000000000000000 - - - - - - - Offset: - - - - - - - -1.000000000000000 - - - 1.000000000000000 - - - 2 - - - 0.050000000000000 - - - 0.200000000000000 - - - -99.000000000000000 - - - 99.000000000000000 - - - - - - - - - - 0 - 0 - - - - Scale X: - - - - - - - 9999.000000000000000 - - - 0.100000000000000 - - - 1.000000000000000 - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 20 - 20 - - - - - - - - - 0 - 0 - - - - Scale Y: - - - - - - - 9999.000000000000000 - - - 0.100000000000000 - - - 1.000000000000000 - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 1 - 20 - - - - - - - - - - - - - - - - SpinSlider - QWidget -
spinslider.h
-
- - ColorButton - QPushButton -
colorbutton.h
-
- - IconedLabel - QFrame -
iconedlabel.h
-
-
- - - - - - - linePath - textChanged(QString) - MaterialMapEditor - mapChanged() - - - 598 - 55 - - - 99 - 73 - - - - - sliderAmount - valueChanged(double) - MaterialMapEditor - mapChanged() - - - 655 - 87 - - - 512 - 37 - - - - - sliderOffset - valueChanged(double) - MaterialMapEditor - mapChanged() - - - 655 - 116 - - - 511 - 65 - - - - - spinScaleX - valueChanged(double) - MaterialMapEditor - mapChanged() - - - 491 - 146 - - - 332 - 164 - - - - - spinScaleY - valueChanged(double) - MaterialMapEditor - mapChanged() - - - 647 - 146 - - - 493 - 164 - - - - - checkMap - toggled(bool) - sliderValue - setHidden(bool) - - - 693 - 15 - - - 626 - 14 - - - - - checkMap - toggled(bool) - widgetMap - setVisible(bool) - - - 686 - 9 - - - 695 - 62 - - - - - sliderValue - valueChanged(double) - MaterialMapEditor - mapChanged() - - - 99 - 15 - - - 130 - 28 - - - - - colorButton - colorChanged(QColor) - MaterialMapEditor - mapChanged() - - - 60 - 11 - - - 75 - 27 - - - - - - mapChanged() - -
diff --git a/qglengine/widgets/materials_editor.cpp b/qglengine/widgets/materials_editor.cpp deleted file mode 100644 index 467e613..0000000 --- a/qglengine/widgets/materials_editor.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - QGL MaterialsEditor - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "materials_editor.h" -#include "ui_materials_editor.h" -#include "material_editor.h" -#include "qglview.h" -#include "glmaterial.h" -#include -#include -#include - - -MaterialsEditor::MaterialsEditor(QWidget * parent): QWidget(parent) { - ui = new Ui::MaterialsEditor(); - ui->setupUi(this); - ui->widgetMaterial->setMaterial(0); - ui->scrollArea->viewport()->setAutoFillBackground(false); - ui->scrollAreaWidgetContents->setAutoFillBackground(false); - view = 0; -} - - -void MaterialsEditor::assignQGLView(QGLView * v) { - view = v; - connect(view, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); - connect(view, SIGNAL(materialsChanged()), this, SLOT(materialsChanged())); - connect(view, SIGNAL(materialThumbnailCreated(Material*)), this, SLOT(materialThumbnailCreated(Material*))); - materialsChanged(); -} - - -bool MaterialsEditor::event(QEvent * e) { - if (e->type() == QEvent::FontChange || e->type() == QEvent::Polish) { - QSize sz = preferredIconSize(1.5, this); - ui->comboMaterial->setIconSize(sz * 3); - ui->buttonRename->setIconSize(sz); - ui->buttonAdd ->setIconSize(sz); - ui->buttonClone ->setIconSize(sz); - ui->buttonDelete->setIconSize(sz); - ui->buttonAssign->setIconSize(sz); - ui->buttonUnset ->setIconSize(sz); - } - return QWidget::event(e); -} - - -void MaterialsEditor::changeEvent(QEvent * e) { - QWidget::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - ui->retranslateUi(this); - break; - default: - break; - } -} - - -Material * MaterialsEditor::currentMaterial() { - if (!view) return 0; - int ind = ui->comboMaterial->currentIndex(); - QVector mats = view->scene()->getMaterials(); - if (ind < 0 || ind >= mats.size()) return 0; - return mats[ind]; -} - - -void MaterialsEditor::selectMaterial(Material * m) { - if (!m) { - ui->comboMaterial->setCurrentIndex(-1); - return; - } - for (int i = 0; i < ui->comboMaterial->count(); ++i) { - if ((Material*)(ui->comboMaterial->itemData(i, Qt::UserRole + 1).value()) == m) { - ui->comboMaterial->setCurrentIndex(i); - break; - } - } -} - - -int MaterialsEditor::indexByMaterial(Material * m) { - if (!m) return -1; - for (int i = 0; i < ui->comboMaterial->count(); ++i) { - if ((Material*)(ui->comboMaterial->itemData(i, Qt::UserRole + 1).value()) == m) - return i; - } - return -1; -} - - -void MaterialsEditor::selectionChanged() { - if (!view) return; - //qDebug() << "selectionChanged"; - ObjectBase * o = view->selectedObject(); - if (o) selectMaterial(o->material()); -} - - -void MaterialsEditor::materialsChanged() { - if (ui->widgetMaterial->ignore_next > 0) { - ui->widgetMaterial->ignore_next--; - return; - } - Material * cm = currentMaterial(); - ui->comboMaterial->clear(); - if (!view) return; - QVector mats = view->scene()->getMaterials(); - for (int i = 0; i < mats.size(); ++i) { - Material * m = mats[i]; - ui->comboMaterial->addItem(QString("[%1] " + m->name).arg(i + 1), QVariant(m->name)); - ui->comboMaterial->setItemData(i, QVariant(quintptr(m)), Qt::UserRole + 1); - ui->comboMaterial->setItemIcon(i, QIcon(QPixmap::fromImage(view->materialThumbnail(m)))); - if (cm == m) ui->comboMaterial->setCurrentIndex(i); - } - -} - - -void MaterialsEditor::materialThumbnailCreated(Material * m) { - //qDebug() << "materialThumbnailCreated" << m; - int i = indexByMaterial(m); - if (i < 0 || !view) return; - //qDebug() << "materialThumbnailCreated set to" << i; - ui->comboMaterial->setItemIcon(i, QIcon(QPixmap::fromImage(view->materialThumbnail(m)))); -} - - -void MaterialsEditor::on_comboMaterial_currentIndexChanged(int index) { - ui->widgetMaterial->setMaterial(currentMaterial()); -} - - -void MaterialsEditor::on_buttonRename_clicked() { - Material * m = currentMaterial(); - if (!m) return; - QString nn = QInputDialog::getText(this, "Materials editor", "Input new name:", QLineEdit::Normal, m->name); - if (nn.isEmpty()) return; - m->name = nn; - int ind = ui->comboMaterial->currentIndex(); - ui->comboMaterial->setItemText(ind, QString("[%1] " + nn).arg(ind + 1)); - ui->comboMaterial->setItemData(ind, nn); -} - - -void MaterialsEditor::on_buttonAdd_clicked() { - if (!view) return; - Material * m = view->scene()->newMaterial(); - materialsChanged(); - selectMaterial(m); -} - - -void MaterialsEditor::on_buttonClone_clicked() { - if (!view) return; - Material * curm = currentMaterial(); - if (!curm) return; - Material * m = view->scene()->newMaterial(curm->name); - QString nm = m->name; - *m = *curm; - m->name = nm; - m->_changed = true; - materialsChanged(); - selectMaterial(m); -} - - -void MaterialsEditor::on_buttonDelete_clicked() { - if (!view) return; - Material * m = currentMaterial(); - if (!m) return; - view->scene()->removeMaterial(m); - materialsChanged(); -} - - -void MaterialsEditor::on_buttonAssign_clicked() { - if (!view) return; - Material * m = currentMaterial(); - ObjectBaseList ol = view->selectedObjects(); - foreach (ObjectBase * o, ol) - o->setMaterial(m, true); -} - - -void MaterialsEditor::on_buttonUnset_clicked() { - if (!view) return; - ObjectBaseList ol = view->selectedObjects(); - foreach (ObjectBase * o, ol) - o->setMaterial(0, true); -} diff --git a/qglengine/widgets/materials_editor.h b/qglengine/widgets/materials_editor.h deleted file mode 100644 index 5cd704d..0000000 --- a/qglengine/widgets/materials_editor.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - QGL MaterialsEditor - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef MATERIALS_EDITOR_H -#define MATERIALS_EDITOR_H - -#include -#include "gltypes.h" - -namespace Ui { - class MaterialsEditor; -} - -class MaterialsEditor: public QWidget -{ - Q_OBJECT -public: - explicit MaterialsEditor(QWidget * parent = 0); - - void assignQGLView(QGLView * v); - -protected: - bool event(QEvent * e); - void changeEvent(QEvent * e); - Material * currentMaterial(); - void selectMaterial(Material * m); - int indexByMaterial(Material * m); - - Ui::MaterialsEditor * ui; - QGLView * view; - Material * mat; - -private slots: - void selectionChanged(); - void materialsChanged(); - void materialThumbnailCreated(Material * m); - - void on_comboMaterial_currentIndexChanged(int index); - void on_buttonRename_clicked(); - void on_buttonAdd_clicked(); - void on_buttonClone_clicked(); - void on_buttonDelete_clicked(); - void on_buttonAssign_clicked(); - void on_buttonUnset_clicked(); - -signals: - void changed(); - -}; - -#endif // MATERIALS_EDITOR_H diff --git a/qglengine/widgets/materials_editor.ui b/qglengine/widgets/materials_editor.ui deleted file mode 100644 index e416569..0000000 --- a/qglengine/widgets/materials_editor.ui +++ /dev/null @@ -1,251 +0,0 @@ - - - MaterialsEditor - - - - 0 - 0 - 386 - 520 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - 0 - 0 - - - - QComboBox::AdjustToMinimumContentsLengthWithIcon - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Vertical - - - - 20 - 1 - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 40 - 10 - - - - - - - - Unset - - - - :/icons/dialog-cancel.png:/icons/dialog-cancel.png - - - - - - - Assign - - - - :/icons/go-jump.png:/icons/go-jump.png - - - - - - - Add - - - - :/icons/list-add.png:/icons/list-add.png - - - - - - - Delete - - - - :/icons/edit-delete.png:/icons/edit-delete.png - - - - - - - Rename ... - - - - :/icons/edit-rename.png:/icons/edit-rename.png - - - - - - - Clone - - - - :/icons/edit-copy.png:/icons/edit-copy.png - - - - - - - - - Qt::Vertical - - - - 20 - 1 - - - - - - - - - - - - - QFrame::NoFrame - - - true - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - 0 - 0 - 386 - 440 - - - - true - - - - 0 - - - 0 - - - 0 - - - - - - - - Qt::Vertical - - - - 20 - 421 - - - - - - - - - - - - - EComboBox - QComboBox -
ecombobox.h
-
- - MaterialEditor - QWidget -
material_editor.h
- 1 -
-
- - - - - - - - - materialChanged() - -
diff --git a/qglengine/widgets/object_editor.cpp b/qglengine/widgets/object_editor.cpp deleted file mode 100644 index 6507ead..0000000 --- a/qglengine/widgets/object_editor.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/* - QGL ObjectEditor - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "object_editor.h" -#include "ui_object_editor.h" -#include "qglview.h" -#include -#include - - -ObjectEditor::ObjectEditor(QWidget * parent): QWidget(parent) { - ui = new Ui::ObjectEditor(); - ui->setupUi(this); - view = 0; - active = true; - ignore_next = false; - on_comboLightType_currentIndexChanged(0); - ui->widgetMain->setEnabled(false); - ui->labelAimDist->hide(); - ui->spinAimDist->hide(); - - QObjectList ol; - ol << ui->spinPosX << ui->spinPosY << ui->spinPosZ << - ui->spinRotationX << ui->spinRotationY << ui->spinRotationZ << - ui->spinScaleX << ui->spinScaleY << ui->spinScaleZ; - foreach (QObject * o, ol) - connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinChanged(double))); - - ol.clear(); - ol << ui->spinLightIntensity << ui->spinLightDecayConst << ui->spinLightDecayLinear << - ui->spinLightDecayQuadratic << ui->spinLightAngleStart << ui->spinLightAngleEnd << - ui->spinAimDist; - foreach (QObject * o, ol) - connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinLightChanged(double))); - - ol.clear(); - ol << ui->spinCameraFOV << ui->spinCameraDepthStart << ui->spinCameraRoll << ui->spinAimDist; - foreach (QObject * o, ol) - connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinCameraChanged(double))); - - ol.clear(); - ol << ui->checkVisible << ui->checkCastShadows << ui->checkReceiveShadows << - ui->checkAcceptLight << ui->checkAcceptFog << - ui->checkCameraMirrorX << ui->checkCameraMirrorY; - foreach (QObject * o, ol) - connect(o, SIGNAL(toggled(bool)), this, SLOT(checkChanged(bool))); - -} - - -void ObjectEditor::assignQGLView(QGLView * v) { - view = v; - connect(view, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); - connect(view, SIGNAL(objectsPositionChanged()), this, SLOT(selectionChanged())); - connect(view->scene(), SIGNAL(treeChanged()), this, SLOT(selectionChanged())); - selectionChanged(); -} - - -void ObjectEditor::changeEvent(QEvent * e) { - QWidget::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - ui->retranslateUi(this); - break; - default: - break; - } -} - - -void ObjectEditor::selectionChanged() { - if (ignore_next) { - ignore_next = false; - return; - } - ui->widgetMain->setEnabled(false); - if (!view) return; - ObjectBaseList sol = view->selectedObjects(true); - if (sol.isEmpty()) { - ui->labelTitle->setText(tr("[No selected]")); - return; - } - ui->widgetMain->setEnabled(true); - if (sol.size() == 1) { - setObject(sol[0]); - return; - } - bool hl = !view->selectedLights().isEmpty(), hc = !view->selectedCameras().isEmpty(); - ui->groupLight ->setVisible(hl); - ui->groupCamera ->setVisible(hc); - ui->labelAimDist->setVisible(hl || hc); - ui->spinAimDist ->setVisible(hl || hc); - ui->labelTitle->setText(tr("[%1 objects]").arg(sol.size())); -} - - -void ObjectEditor::setObject(ObjectBase * o) { - active = false; - ui->labelTitle->setText(o->name()); - ui->spinPosX->setValue(o->posX()); - ui->spinPosY->setValue(o->posY()); - ui->spinPosZ->setValue(o->posZ()); - ui->spinRotationX->setValue(o->rotationX()); - ui->spinRotationY->setValue(o->rotationY()); - ui->spinRotationZ->setValue(o->rotationZ()); - ui->spinScaleX->setValue(o->scaleX()); - ui->spinScaleY->setValue(o->scaleY()); - ui->spinScaleZ->setValue(o->scaleZ()); - ui->checkVisible->setChecked(o->isVisible()); - ui->checkAcceptLight->setChecked(o->isAcceptLight()); - ui->checkAcceptFog->setChecked(o->isAcceptFog()); - ui->checkCastShadows->setChecked(o->isCastShadows()); - ui->checkReceiveShadows->setChecked(o->isReceiveShadows()); - ui->buttonColor->setColor(o->color()); - bool is_l = o->type() == ObjectBase::glLight; - bool is_c = o->type() == ObjectBase::glCamera; - ui->labelAimDist->setVisible(is_l || is_c); - ui->spinAimDist ->setVisible(is_l || is_c); - ui->groupLight ->setVisible(is_l); - ui->groupCamera ->setVisible(is_c); - if (is_l) { - Light * l = globject_cast(o); - //bool is_dir = l->light_type == Light::Directional, is_cone = l->light_type == Light::Cone; - ui->comboLightType->setCurrentIndex(l->light_type); - ui->spinLightIntensity->setValue(l->intensity); - ui->spinLightDecayConst->setValue(l->decay_const); - ui->spinLightDecayLinear->setValue(l->decay_linear); - ui->spinLightDecayQuadratic->setValue(l->decay_quadratic); - ui->spinLightAngleStart->setValue(l->angle_start); - ui->spinLightAngleEnd->setValue(l->angle_end); - ui->spinAimDist->setValue(l->distance()); - on_comboLightType_currentIndexChanged(ui->comboLightType->currentIndex()); - } - if (is_c) { - Camera * c = globject_cast(o); - ui->checkCameraMirrorX->setChecked(c->isMirrorX()); - ui->checkCameraMirrorY->setChecked(c->isMirrorY()); - ui->spinCameraFOV->setValue(c->FOV()); - ui->spinCameraRoll->setValue(c->angleRoll()); - ui->spinCameraDepthStart->setValue(c->depthStart()); - ui->spinAimDist->setValue(c->distance()); - } - active = true; -} - - -void ObjectEditor::on_spinLightAngleStart_valueChanged(double v) { - if (ui->spinLightAngleEnd->value() < v) - ui->spinLightAngleEnd->setValue(v); -} - - -void ObjectEditor::on_spinLightAngleEnd_valueChanged(double v) { - if (ui->spinLightAngleStart->value() > v) - ui->spinLightAngleStart->setValue(v); -} - - -void ObjectEditor::on_comboLightType_currentIndexChanged(int index) { - bool ang = (index == Light::Cone); - ui->labelLightAngle ->setVisible(ang); - ui->labelLightAngleDash->setVisible(ang); - ui->spinLightAngleStart->setVisible(ang); - ui->spinLightAngleEnd ->setVisible(ang); - if (!view || !active) return; - QList sll = view->selectedLights(); - foreach (Light * o, sll) { - o->light_type = (Light::Type)index; - o->apply(); - } -} - - -void ObjectEditor::on_buttonColor_colorChanged(const QColor & v) { - if (!view || !active) return; - ObjectBaseList sol = view->selectedObjects(); - foreach (ObjectBase * o, sol) - o->setColor(v); - QList sll = view->selectedLights(); - foreach (Light * o, sll) - o->apply(); -} - - -void ObjectEditor::spinChanged(double v) { - if (!view || !active) return; - ObjectBaseList sol = view->selectedObjects(true); - QObject * s = sender(); - foreach (ObjectBase * o, sol) { - if (s == ui->spinPosX ) o->setPosX (v); - if (s == ui->spinPosY ) o->setPosY (v); - if (s == ui->spinPosZ ) o->setPosZ (v); - if (s == ui->spinRotationX) o->setRotationX(v); - if (s == ui->spinRotationY) o->setRotationY(v); - if (s == ui->spinRotationZ) o->setRotationZ(v); - if (s == ui->spinScaleX ) o->setScaleX (v); - if (s == ui->spinScaleY ) o->setScaleY (v); - if (s == ui->spinScaleZ ) o->setScaleZ (v); - } - ignore_next = true; -} - - -void ObjectEditor::spinLightChanged(double v) { - if (!view || !active) return; - QList sll = view->selectedLights(); - QObject * s = sender(); - foreach (Light * o, sll) { - if (s == ui->spinLightIntensity ) o->intensity = v; - if (s == ui->spinLightDecayConst ) o->decay_const = v; - if (s == ui->spinLightDecayLinear ) o->decay_linear = v; - if (s == ui->spinLightDecayQuadratic) o->decay_quadratic = v; - if (s == ui->spinLightAngleStart ) o->angle_start = v; - if (s == ui->spinLightAngleEnd ) o->angle_end = v; - if (s == ui->spinAimDist ) o->setDistance(v); - o->apply(); - } - ignore_next = true; -} - - -void ObjectEditor::spinCameraChanged(double v) { - if (!view || !active) return; - QList scl = view->selectedCameras(); - QObject * s = sender(); - foreach (Camera * o, scl) { - if (s == ui->spinCameraFOV ) o->setFOV (v); - if (s == ui->spinCameraRoll ) o->setAngleRoll (v); - if (s == ui->spinCameraDepthStart) o->setDepthStart(v); - if (s == ui->spinAimDist ) o->setDistance (v); - } - ignore_next = true; -} - - -void ObjectEditor::checkChanged(bool v) { - if (!view || !active) return; - ObjectBaseList sol = view->selectedObjects(); - QList scl = view->selectedCameras(); - QObject * s = sender(); - foreach (ObjectBase * o, sol) { - if (s == ui->checkVisible ) o->setVisible (v); - if (s == ui->checkCastShadows ) o->setCastShadows (v); - if (s == ui->checkReceiveShadows) o->setReceiveShadows(v); - if (s == ui->checkAcceptLight ) o->setAcceptLight (v); - if (s == ui->checkAcceptFog ) o->setAcceptFog (v); - } - foreach (Camera * o, scl) { - if (s == ui->checkCameraMirrorX ) o->setMirrorX(v); - if (s == ui->checkCameraMirrorY ) o->setMirrorY(v); - } -} diff --git a/qglengine/widgets/object_editor.h b/qglengine/widgets/object_editor.h deleted file mode 100644 index 89311f1..0000000 --- a/qglengine/widgets/object_editor.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - QGL ObjectEditor - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef OBJECT_EDITOR_H -#define OBJECT_EDITOR_H - -#include -#include "globject.h" - -namespace Ui { - class ObjectEditor; -} - -class ObjectEditor: public QWidget -{ - Q_OBJECT -public: - explicit ObjectEditor(QWidget * parent = 0); - - void assignQGLView(QGLView * v); - -protected: - void changeEvent(QEvent * e); - void setObject(ObjectBase * o); - - Ui::ObjectEditor * ui; - QGLView * view; - bool active, ignore_next; - -private slots: - void selectionChanged(); - void on_spinLightAngleStart_valueChanged(double v); - void on_spinLightAngleEnd_valueChanged(double v); - - void on_comboLightType_currentIndexChanged(int index); - void on_buttonColor_colorChanged(const QColor &v); - void spinChanged(double v); - void spinLightChanged(double v); - void spinCameraChanged(double v); - void checkChanged(bool v); - -signals: - void changed(); - -}; - -#endif // OBJECT_EDITOR_H diff --git a/qglengine/widgets/object_editor.ui b/qglengine/widgets/object_editor.ui deleted file mode 100644 index 58ec410..0000000 --- a/qglengine/widgets/object_editor.ui +++ /dev/null @@ -1,782 +0,0 @@ - - - ObjectEditor - - - - 0 - 0 - 466 - 778 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - font: bold; - - - [No selected] - - - Qt::AlignCenter - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Position - - - - - - - 0 - 0 - - - - X: - - - - - - - - - - - 0 - 0 - - - - Y: - - - - - - - - - - - 0 - 0 - - - - Z: - - - - - - - - - - - - - Rotation - - - - - - - 0 - 0 - - - - X: - - - - - - - -360.000000000000000 - - - 360.000000000000000 - - - 1 - - - 4.500000000000000 - - - 90.000000000000000 - - - ° - - - QSlider::TicksAbove - - - 90 - - - - - - - - 0 - 0 - - - - Y: - - - - - - - -360.000000000000000 - - - 360.000000000000000 - - - 4.500000000000000 - - - 90.000000000000000 - - - ° - - - QSlider::TicksAbove - - - 90 - - - - - - - - 0 - 0 - - - - Z: - - - - - - - -360.000000000000000 - - - 360.000000000000000 - - - 4.500000000000000 - - - 90.000000000000000 - - - ° - - - QSlider::TicksAbove - - - 90 - - - - - - - - - - Scale - - - - - - - 0 - 0 - - - - X: - - - - - - - - - - - 0 - 0 - - - - Y: - - - - - - - - - - - 0 - 0 - - - - Z: - - - - - - - - - - - - - - - Accept fog - - - - - - - Accept light - - - - - - - Visible - - - - - - - Cast shadows - - - - - - - Receive shadows - - - - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 0 - 0 - - - - Color: - - - - - - - - - - - 0 - 0 - - - - Aim distance: - - - - - - - - - - - - Light - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - Type: - - - - - - - - Omni - - - - - Cone - - - - - Directional - - - - - - - - Intensity: - - - - - - - 0.000000000000000 - - - 10.000000000000000 - - - 1.000000000000000 - - - 3 - - - 0.100000000000000 - - - 1.000000000000000 - - - true - - - 999.000000000000000 - - - - - - - Decay ^0: - - - - - - - 0.000000000000000 - - - 10.000000000000000 - - - 1.000000000000000 - - - 3 - - - 0.100000000000000 - - - 1.000000000000000 - - - true - - - 999.000000000000000 - - - - - - - Decay ^1: - - - - - - - 0.000000000000000 - - - 10.000000000000000 - - - 0.000000000000000 - - - 3 - - - 0.100000000000000 - - - 1.000000000000000 - - - true - - - 999.000000000000000 - - - - - - - Decay ^2: - - - - - - - 0.000000000000000 - - - 10.000000000000000 - - - 0.000000000000000 - - - 3 - - - 0.100000000000000 - - - 1.000000000000000 - - - true - - - 999.000000000000000 - - - - - - - Angle: - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0.000000000000000 - - - 180.000000000000000 - - - 1 - - - 5.000000000000000 - - - 30.000000000000000 - - - ° - - - - - - - - - - - - - - - 0.000000000000000 - - - 180.000000000000000 - - - 1 - - - 5.000000000000000 - - - 30.000000000000000 - - - ° - - - - - - - - - - - - - Camera - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - Depth start: - - - - - - - FOV: - - - - - - - 1.000000000000000 - - - 179.900000000000006 - - - 60.000000000000000 - - - 1 - - - 5.000000000000000 - - - 30.000000000000000 - - - ° - - - - - - - - - Mirror Y - - - - - - - Mirror X - - - - - - - - - 5 - - - 999999999.000000000000000 - - - 0.100000000000000 - - - - - - - -180.000000000000000 - - - 180.000000000000000 - - - 0.000000000000000 - - - 1 - - - 5.000000000000000 - - - 30.000000000000000 - - - ° - - - - - - - Roll: - - - - - - - - - - - - - - SpinSlider - QWidget -
spinslider.h
-
- - ColorButton - QPushButton -
colorbutton.h
-
- - ScrollSpinBox - QWidget -
scroll_spin_box.h
-
-
- - - - objectChanged() - -
diff --git a/qglengine/widgets/primitiveeditor.cpp b/qglengine/widgets/primitiveeditor.cpp deleted file mode 100644 index 4613004..0000000 --- a/qglengine/widgets/primitiveeditor.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/* - QGL PrimitiveEditor - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "primitiveeditor.h" -#include "ui_primitiveeditor.h" -#include -#include "glprimitives.h" -#include "glmesh.h" - - -PrimitiveEditor::PrimitiveEditor(QWidget *parent) : QWidget(parent), ui(new Ui::PrimitiveEditor) { - view = 0; - can_replace = false; - ui->setupUi(this); -#if QT_VERSION >= QT_VERSION_CHECK(5,12,0) - ui->spinSegments->setStepType(QAbstractSpinBox::AdaptiveDecimalStepType); - ui->spinSegments2->setStepType(QAbstractSpinBox::AdaptiveDecimalStepType); -#endif - editors[Plane] << ui->widgetWidth; - editors[Plane] << ui->widgetLength; - editors[Cube] << ui->widgetWidth; - editors[Cube] << ui->widgetLength; - editors[Cube] << ui->widgetHeight; - editors[Ellipsoid] << ui->widgetRadius1; - editors[Ellipsoid] << ui->widgetSegments; - editors[Ellipsoid] << ui->widgetSegments2; - editors[Ellipsoid] << ui->widgetAngle; - editors[Disc] << ui->widgetRadius1; - editors[Disc] << ui->widgetSegments; - editors[Disc] << ui->widgetAngle; - editors[Cone] << ui->widgetRadius1; - editors[Cone] << ui->widgetHeight; - editors[Cone] << ui->widgetSegments; - editors[Cylinder] << ui->widgetRadius1; - editors[Cylinder] << ui->widgetHeight; - editors[Cylinder] << ui->widgetSegments; - editors[Cylinder] << ui->widgetAngle; - editors[Torus] << ui->widgetRadius1; - editors[Torus] << ui->widgetRadius2; - editors[Torus] << ui->widgetSegments; - editors[Torus] << ui->widgetSegments2; - editors[Torus] << ui->widgetAngle; - QSet all; - QMetaEnum me = metaObject()->enumerator(0); - for (int i=0; icomboPrimitives->addItem(me.key(i)); - all.unite(editors[(PrimitiveType)me.value(i)].toSet()); - } - all_editors = all.toList(); - foreach (QWidget * w, all_editors) { - if (w->layout()) w->layout()->setContentsMargins(0, layout()->spacing(), 0, 0); - } - - ui->comboPrimitives->setCurrentIndex(Plane); - on_comboPrimitives_currentIndexChanged(ui->comboPrimitives->currentIndex()); -} - - -PrimitiveEditor::~PrimitiveEditor() { - delete ui; -} - - -void PrimitiveEditor::assignQGLView(QGLView * v) { - view = v; - connect(view, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); - selectionChanged(); -} - - -Mesh * PrimitiveEditor::createMesh(QVariantList & params) { - Mesh * m = 0; - PrimitiveType pt = (PrimitiveType)ui->comboPrimitives->currentIndex(); - params << pt; - switch (pt) { - case Plane: - m = Primitive::plane(ui->spinWidth->value(), - ui->spinLength->value()); - params << ui->spinWidth->value() - << ui->spinLength->value(); - break; - case Cube: - m = Primitive::cube(ui->spinWidth->value(), - ui->spinLength->value(), - ui->spinHeight->value()); - params << ui->spinWidth->value() - << ui->spinLength->value() - << ui->spinHeight->value(); - break; - case Ellipsoid: - m = Primitive::ellipsoid(ui->spinSegments->value(), - ui->spinSegments2->value(), - ui->spinRadius->value(), - ui->spinAngle->value()); - params << ui->spinSegments->value() - << ui->spinSegments2->value() - << ui->spinRadius->value() - << ui->spinAngle->value(); - break; - case Disc: - m = Primitive::disc(ui->spinSegments->value(), - ui->spinRadius->value(), - ui->spinAngle->value()); - params << ui->spinSegments->value() - << ui->spinRadius->value() - << ui->spinAngle->value(); - break; - case Cone: - m = Primitive::cone(ui->spinSegments->value(), - ui->spinRadius->value(), - ui->spinHeight->value()); - params << ui->spinSegments->value() - << ui->spinRadius->value() - << ui->spinHeight->value(); - break; - case Cylinder: - m = Primitive::cylinder(ui->spinSegments->value(), - ui->spinRadius->value(), - ui->spinHeight->value(), - ui->spinAngle->value()); - params << ui->spinSegments->value() - << ui->spinRadius->value() - << ui->spinHeight->value() - << ui->spinAngle->value(); - break; - case Torus: - m = Primitive::torus(ui->spinSegments->value(), - ui->spinSegments2->value(), - ui->spinRadius->value(), - ui->spinRadius2->value(), - ui->spinAngle->value()); - params << ui->spinSegments->value() - << ui->spinSegments2->value() - << ui->spinRadius->value() - << ui->spinRadius2->value() - << ui->spinAngle->value(); - break; - default: return 0; - } - params << ui->flipNormals->isChecked(); - params << ui->colorButton->color(); - if (ui->flipNormals->isChecked()) - m->flipNormals(); - return m; -} - - -void PrimitiveEditor::showEditors() { - foreach (QWidget * w, all_editors) w->hide(); - PrimitiveType pt = (PrimitiveType)ui->comboPrimitives->currentIndex(); - QList wds = editors[pt]; - foreach (QWidget * w, wds) w->show(); -} - - -void PrimitiveEditor::selectionChanged() { - ObjectBase * so = view->selectedObject();\ - can_replace = false; - if (so) { - QVariantList vl = so->property("primitive", &can_replace).toList(); - if (can_replace && !vl.isEmpty()) { - PrimitiveType pt = (PrimitiveType)vl.takeFirst().toInt(); - ui->comboPrimitives->setCurrentIndex(pt); - switch (pt) { - case Plane: - ui->spinWidth->setValue(vl.takeFirst().toDouble()); - ui->spinLength->setValue(vl.takeFirst().toDouble()); - break; - case Cube: - ui->spinWidth->setValue(vl.takeFirst().toDouble()); - ui->spinLength->setValue(vl.takeFirst().toDouble()); - ui->spinHeight->setValue(vl.takeFirst().toDouble()); - break; - case Ellipsoid: - ui->spinSegments->setValue(vl.takeFirst().toDouble()); - ui->spinSegments2->setValue(vl.takeFirst().toDouble()); - ui->spinRadius->setValue(vl.takeFirst().toDouble()); - ui->spinAngle->setValue(vl.takeFirst().toDouble()); - break; - case Disc: - ui->spinSegments->setValue(vl.takeFirst().toDouble()); - ui->spinRadius->setValue(vl.takeFirst().toDouble()); - ui->spinAngle->setValue(vl.takeFirst().toDouble()); - break; - case Cone: - ui->spinSegments->setValue(vl.takeFirst().toDouble()); - ui->spinRadius->setValue(vl.takeFirst().toDouble()); - ui->spinHeight->setValue(vl.takeFirst().toDouble()); - break; - case Cylinder: - ui->spinSegments->setValue(vl.takeFirst().toDouble()); - ui->spinRadius->setValue(vl.takeFirst().toDouble()); - ui->spinHeight->setValue(vl.takeFirst().toDouble()); - ui->spinAngle->setValue(vl.takeFirst().toDouble()); - break; - case Torus: - ui->spinSegments->setValue(vl.takeFirst().toDouble()); - ui->spinSegments2->setValue(vl.takeFirst().toDouble()); - ui->spinRadius->setValue(vl.takeFirst().toDouble()); - ui->spinRadius2->setValue(vl.takeFirst().toDouble()); - ui->spinAngle->setValue(vl.takeFirst().toDouble()); - break; - } - ui->flipNormals->setChecked(vl.takeFirst().toBool()); - ui->colorButton->setColor(vl.takeFirst().value()); - } - } -} - - -void PrimitiveEditor::replaceMesh() { - if (!view) return; - if (!can_replace) return; - ObjectBase * so = view->selectedObject(); - if (!so) return; - QVariantList params; - Mesh * m = createMesh(params); - if (!m) return; - so->setMesh(m); - so->setColor(ui->colorButton->color()); - so->setName(ui->comboPrimitives->currentText()); - so->setProperty("primitive", params); - delete m; -} - - -void PrimitiveEditor::on_buttonAdd_clicked() { - if (!view) return; - QVariantList params; - Mesh * m = createMesh(params); - if (!m) return; - ObjectBase * o = new ObjectBase(m); - o->setColor(ui->colorButton->color()); - o->setName(ui->comboPrimitives->currentText()); - o->setProperty("primitive", params); - view->scene()->addObject(o); - view->scene()->selectObject(o); - delete m; -} - - -void PrimitiveEditor::on_comboPrimitives_currentIndexChanged(int index) { - showEditors(); -} diff --git a/qglengine/widgets/primitiveeditor.h b/qglengine/widgets/primitiveeditor.h deleted file mode 100644 index d91c77f..0000000 --- a/qglengine/widgets/primitiveeditor.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - QGL PrimitiveEditor - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef PRIMITIVEEDITOR_H -#define PRIMITIVEEDITOR_H - -#include -#include "qglview.h" - - -namespace Ui { -class PrimitiveEditor; -} - - -class PrimitiveEditor : public QWidget { - Q_OBJECT -public: - enum PrimitiveType { - Plane, - Cube, - Ellipsoid, - Disc, - Cone, - Cylinder, - Torus - }; - Q_ENUMS(PrimitiveType) - - explicit PrimitiveEditor(QWidget *parent = nullptr); - ~PrimitiveEditor(); - - void assignQGLView(QGLView * v); - -protected: - Mesh * createMesh(QVariantList & params); - void showEditors(); - - Ui::PrimitiveEditor *ui; - QGLView * view; - QMap > editors; - QList all_editors; - bool can_replace; - -private slots: - void selectionChanged(); - void replaceMesh(); - void on_buttonAdd_clicked(); - void on_comboPrimitives_currentIndexChanged(int index); -}; - - -#endif // PRIMITIVEEDITOR_H diff --git a/qglengine/widgets/primitiveeditor.ui b/qglengine/widgets/primitiveeditor.ui deleted file mode 100644 index 2d2c9d9..0000000 --- a/qglengine/widgets/primitiveeditor.ui +++ /dev/null @@ -1,597 +0,0 @@ - - - PrimitiveEditor - - - - 0 - 0 - 360 - 536 - - - - Form - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - - - 0 - - - 0 - - - - - Width: - - - - - - - 1.000000000000000 - - - - - - - - - - - 0 - - - 0 - - - 0 - - - - - Length: - - - - - - - 1.000000000000000 - - - - - - - - - - - 0 - - - 0 - - - 0 - - - - - Height - - - - - - - 1.000000000000000 - - - - - - - - - - - 0 - - - 0 - - - 0 - - - - - Radius 1: - - - - - - - 1.000000000000000 - - - - - - - - - - - 0 - - - 0 - - - 0 - - - - - Radius 2: - - - - - - - 1.000000000000000 - - - - - - - - - - - 0 - - - 0 - - - 0 - - - - - Angle: - - - - - - - 360.000000000000000 - - - 360.000000000000000 - - - 4.500000000000000 - - - 90.000000000000000 - - - ° - - - QSlider::TicksAbove - - - 90 - - - - - - - - - - - 0 - - - 0 - - - 0 - - - - - Segments: - - - - - - - 1 - - - 1000 - - - 1 - - - 16 - - - - - - - - - - - 0 - - - 0 - - - 0 - - - - - Segments 2: - - - - - - - 1 - - - 1000 - - - 1 - - - 16 - - - - - - - - - - - 0 - - - 0 - - - 0 - - - - - Color: - - - - - - - - 255 - 255 - 255 - - - - - - - - - - - - - - Flip normals - - - - - - - Qt::Vertical - - - - 20 - 176 - - - - - - - - - - Add - - - - :/icons/list-add.png:/icons/list-add.png - - - - - - - - - - SpinSlider - QWidget -
spinslider.h
-
- - ColorButton - QPushButton -
colorbutton.h
-
- - EComboBox - QComboBox -
ecombobox.h
-
- - ScrollSpinBox - QWidget -
scroll_spin_box.h
-
-
- - - - - - spinWidth - valueChanged(double) - PrimitiveEditor - replaceMesh() - - - 331 - 51 - - - 368 - 45 - - - - - spinLength - valueChanged(double) - PrimitiveEditor - replaceMesh() - - - 330 - 84 - - - 369 - 82 - - - - - spinHeight - valueChanged(double) - PrimitiveEditor - replaceMesh() - - - 334 - 116 - - - 366 - 114 - - - - - spinRadius - valueChanged(double) - PrimitiveEditor - replaceMesh() - - - 332 - 144 - - - 370 - 145 - - - - - spinRadius2 - valueChanged(double) - PrimitiveEditor - replaceMesh() - - - 334 - 186 - - - 371 - 181 - - - - - spinAngle - valueChanged(double) - PrimitiveEditor - replaceMesh() - - - 335 - 210 - - - 372 - 213 - - - - - spinSegments - valueChanged(int) - PrimitiveEditor - replaceMesh() - - - 329 - 246 - - - 370 - 247 - - - - - spinSegments2 - valueChanged(int) - PrimitiveEditor - replaceMesh() - - - 336 - 284 - - - 372 - 279 - - - - - flipNormals - toggled(bool) - PrimitiveEditor - replaceMesh() - - - 70 - 344 - - - 370 - 341 - - - - - comboPrimitives - currentIndexChanged(int) - PrimitiveEditor - replaceMesh() - - - 348 - 9 - - - 367 - 9 - - - - - colorButton - colorChanged(QColor) - PrimitiveEditor - replaceMesh() - - - 271 - 285 - - - 179 - 267 - - - - - - replaceMesh() - -
diff --git a/qglengine/widgets/propertyeditor.cpp b/qglengine/widgets/propertyeditor.cpp deleted file mode 100644 index b4c568e..0000000 --- a/qglengine/widgets/propertyeditor.cpp +++ /dev/null @@ -1,426 +0,0 @@ -/* - QGL PropertyEditor - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "propertyeditor.h" - - -QWidget * Delegate::widgetForProperty(QWidget * parent, const QModelIndex & index) const { - QWidget * w = 0; - int type = 0; - QVariant value = index.data(Qt::UserRole); - if (index.data(Qt::UserRole + 2).toString() == "__flags") return 0; - if (index.data(Qt::UserRole + 1).toString() == "__flag") { - qulonglong key = index.data(Qt::UserRole).toULongLong(); - value = index.parent().data(Qt::UserRole); - //QMetaProperty prop = index.parent().data(Qt::UserRole + 1).value(); - w = new QCheckBox(parent); type = 14; ((QCheckBox*)w)->setChecked(((value.toULongLong() & key) == key && key != 0) || (value.toULongLong() == 0 && key == 0)); - ((QCheckBox*)w)->setText("0x" + QString::number(key, 16).toUpper()); - connect((QCheckBox*)w, SIGNAL(clicked(bool)), this, SLOT(changedFlag())); - //qDebug() << prop.enumerator().name(); - } else { - if (value.canConvert()) { - PropertyValuePair prop = value.value(); - if (prop.first.isEnumType()) { - w = new QComboBox(parent); type = 13; ((QComboBox*)w)->setCurrentIndex(value.toInt()); - w->setProperty("__prop", QVariant::fromValue(prop.first)); - QMetaEnum menum = prop.first.enumerator(); - for (int i = 0; i < menum.keyCount(); ++i) { - ((QComboBox*)w)->addItem(QString(menum.key(i)) + " (0x" + QString::number(menum.value(i), 16).toUpper() + ")", menum.value(i)); - if (menum.value(i) == prop.second.toInt()) - ((QComboBox*)w)->setCurrentIndex(i); - } - connect((QComboBox*)w, SIGNAL(currentIndexChanged(int)), this, SLOT(changed())); - } - } else { - switch (value.type()) { - case QVariant::Int: w = new QSpinBox(parent); type = 2; ((QSpinBox*)w)->setRange(-0x7FFFFFFF, 0x7FFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break; - case QVariant::UInt: w = new QSpinBox(parent); type = 3; ((QSpinBox*)w)->setRange(0, 0xFFFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break; - case QVariant::LongLong: w = new QSpinBox(parent); type = 4; ((QSpinBox*)w)->setRange(-0x7FFFFFFF, 0x7FFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break; - case QVariant::ULongLong: w = new QSpinBox(parent); type = 5; ((QSpinBox*)w)->setRange(0, 0xFFFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break; - case QVariant::Double: w = new QDoubleSpinBox(parent); type = 6; ((QDoubleSpinBox*)w)->setRange(-999999999, 999999999); ((QDoubleSpinBox*)w)->setDecimals(3); connect((QDoubleSpinBox*)w, SIGNAL(valueChanged(double)), this, SLOT(changed())); break; - case QVariant::Bool: w = new QCheckBox(parent); type = 7; ((QCheckBox*)w)->setChecked(value.toBool()); connect((QCheckBox*)w, SIGNAL(toggled(bool)), this, SLOT(changed())); break; - case QVariant::Color: w = new ColorButton(parent); type = 8; ((ColorButton*)w)->setUseAlphaChannel(true); ((ColorButton*)w)->setColor(value.value()); connect((ColorButton*)w, SIGNAL(colorChanged(QColor)), this, SLOT(changed())); break; - case QVariant::Point: w = new QPointEdit(parent); type = 9; ((QPointEdit*)w)->setDecimals(0); ((QPointEdit*)w)->setValue(QPointF(value.toPoint())); connect((QPointEdit*)w, SIGNAL(valueChanged(QPointF)), this, SLOT(changed())); break; - case QVariant::PointF: w = new QPointEdit(parent); type = 10; ((QPointEdit*)w)->setDecimals(3); ((QPointEdit*)w)->setValue(value.toPointF()); connect((QPointEdit*)w, SIGNAL(valueChanged(QPointF)), this, SLOT(changed())); break; - case QVariant::Rect: w = new QRectEdit(parent); type = 11; ((QRectEdit*)w)->setDecimals(0); ((QRectEdit*)w)->setValue(QRectF(value.toRect())); connect((QRectEdit*)w, SIGNAL(valueChanged(QRectF)), this, SLOT(changed())); break; - case QVariant::RectF: w = new QRectEdit(parent); type = 12; ((QRectEdit*)w)->setDecimals(3); ((QRectEdit*)w)->setValue(value.toRectF()); connect((QRectEdit*)w, SIGNAL(valueChanged(QRectF)), this, SLOT(changed())); break; - case QVariant::String: default: w = new CLineEdit(parent); type = 1; ((CLineEdit*)w)->setDefaultText(value.toString()); connect((CLineEdit*)w, SIGNAL(textChanged(QString)), this, SLOT(changed())); break; - } - } - } - if (w == 0) return 0; - /*QPalette pal = w->palette(); - pal.setColor(QPalette::Window, Qt::white); - w->setPalette(pal);*/ - w->setAutoFillBackground(true); - w->setProperty("__type", type); - return w; -} - - -void Delegate::setWidgetProperty(QWidget * w, const QVariant & value) const { - if (w == 0) return; - switch (w->property("__type").toInt()) { - case 1: ((CLineEdit*)w)->setText(value.toString()); break; - case 2: case 3: case 4: case 5: ((QSpinBox*)w)->setValue(value.toInt()); break; - case 6: ((QDoubleSpinBox*)w)->setValue(value.toDouble()); break; - case 7: ((QCheckBox*)w)->setChecked(value.toBool()); break; - case 8: ((ColorButton*)w)->setColor(value.value()); break; - case 9: ((QPointEdit*)w)->setValue(value.value()); break; - case 10: ((QPointEdit*)w)->setValue(value.value()); break; - case 11: ((QRectEdit*)w)->setValue(value.value()); break; - case 12: ((QRectEdit*)w)->setValue(value.value()); break; - } -} - - -const QVariant Delegate::widgetProperty(QWidget * w) const { - if (w == 0) return QVariant(); - switch (w->property("__type").toInt()) { - case 1: return QVariant::fromValue(((CLineEdit*)w)->text()); break; - case 2: return QVariant::fromValue(((QSpinBox*)w)->value()); break; - case 3: return QVariant::fromValue(((QSpinBox*)w)->value()); break; - case 4: return QVariant::fromValue(((QSpinBox*)w)->value()); break; - case 5: return QVariant::fromValue(((QSpinBox*)w)->value()); break; - case 6: return QVariant::fromValue(((QDoubleSpinBox*)w)->value()); break; - case 7: return QVariant::fromValue(((QCheckBox*)w)->isChecked()); break; - case 8: return QVariant::fromValue(((ColorButton*)w)->color()); break; - case 9: return QVariant::fromValue(((QPointEdit*)w)->value().toPoint()); break; - case 10: return QVariant::fromValue(((QPointEdit*)w)->value()); break; - case 11: return QVariant::fromValue(((QRectEdit*)w)->value().toRect()); break; - case 12: return QVariant::fromValue(((QRectEdit*)w)->value()); break; - case 13: return QVariant::fromValue(PropertyValuePair(w->property("__prop").value(), ((QComboBox*)w)->itemData(((QComboBox*)w)->currentIndex()))); break; - default: return QVariant(); break; - } - return QVariant(); -} - - -void Delegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const { - if (index.data(Qt::UserRole + 1).toString() != "__flag") - model->setData(index, widgetProperty(editor), Qt::UserRole); -} - - -void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { - QStyledItemDelegate::paint(painter, option, index); - QVariant value = index.data(Qt::UserRole); - QStyle * style = QApplication::style(); - QStyleOption * so = 0; - QStyleOptionComplex * soc = 0; - QString text; - QRect rect; - QPalette::ColorRole role = (option.state.testFlag(QStyle::State_Selected) && option.state.testFlag(QStyle::State_Active) ? QPalette::HighlightedText : QPalette::WindowText); - if (index.data(Qt::UserRole + 2).toString() == "__flags") { - text = "0x" + QString::number(value.toInt(), 16).toUpper(); - style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), - Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); - return; - } - if (index.data(Qt::UserRole + 1) == "__flag") { - qulonglong key = index.data(Qt::UserRole).toULongLong(); - value = index.parent().data(Qt::UserRole); - so = new QStyleOptionButton(); - so->rect = option.rect; - so->palette = option.palette; - so->fontMetrics = option.fontMetrics; - ((QStyleOptionButton*)so)->state = (((value.toULongLong() & key) == key && key != 0) || (value.toULongLong() == 0 && key == 0) ? QStyle::State_On : QStyle::State_Off) | option.state; - ((QStyleOptionButton*)so)->text = "0x" + QString::number(key, 16).toUpper(); - if (option.state.testFlag(QStyle::State_Selected)) - so->palette.setColor(QPalette::WindowText, so->palette.color(QPalette::HighlightedText)); - style->drawControl(QStyle::CE_CheckBox, so, painter); - } else { - if (value.canConvert()) { - PropertyValuePair prop = value.value(); - if (prop.first.isEnumType()) { - QMetaEnum menum = prop.first.enumerator(); - for (int i = 0; i < menum.keyCount(); ++i) { - if (menum.value(i) == prop.second.toInt()) { - text = QString(menum.key(i)) + " (0x" + QString::number(menum.value(i), 16).toUpper() + ")"; - break; - } - } - style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), - Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); - } - } else { - switch (value.type()) { - case QVariant::Int: - text.setNum(value.toInt()); - style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), - Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); - break; - case QVariant::UInt: - text.setNum(value.toUInt()); - style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), - Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); - break; - case QVariant::LongLong: - text.setNum(value.toLongLong()); - style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), - Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); - break; - case QVariant::ULongLong: - text.setNum(value.toULongLong()); - style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), - Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); - break; - case QVariant::Double: - text.setNum(value.toDouble(), 'f', 3); - style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), - Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); - break; - case QVariant::Bool: - so = new QStyleOptionButton(); - so->rect = option.rect; - so->state = option.state; - so->palette = option.palette; - so->fontMetrics = option.fontMetrics; - ((QStyleOptionButton*)so)->state = (value.toBool() ? QStyle::State_On : QStyle::State_Off) | option.state; - style->drawControl(QStyle::CE_CheckBox, so, painter); - break; - case QVariant::Color: - rect = option.rect;//style->subElementRect(QStyle::QStyle::SE_FrameContents, so); - rect.setRect(rect.x() + 3, rect.y() + 3, rect.width() - 6, rect.height() - 6); - painter->fillRect(rect, ab); - painter->fillRect(rect, value.value()); - break; - case QVariant::Point: - text = pointString(value.toPoint()); - style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), - Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); - break; - case QVariant::PointF: - text = pointString(value.toPointF()); - style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), - Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); - break; - case QVariant::Rect: - text = rectString(value.toRect()); - style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), - Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); - break; - case QVariant::RectF: - text = rectString(value.toRectF()); - style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), - Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); - break; - case QVariant::String: default: - style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, value.toString()), - Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, value.toString(), role); - break; - } - } - } - /*so = new QStyleOptionFrame(); - so->rect = option.rect; - so->state = option.state; - so->palette = option.palette; - so->fontMetrics = option.fontMetrics; - ((QStyleOptionFrame*)so)->state = (value.toBool() ? QStyle::State_On : QStyle::State_Off); - style->drawPrimitive(QStyle::PE_PanelLineEdit, so, painter); - style->drawPrimitive(QStyle::PE_FrameLineEdit, so, painter); - break;*/ - if (so != 0) delete so; - if (soc != 0) delete soc; - -} - - -void Delegate::changedFlag() { - QAbstractItemModel * model = const_cast(cmi.model()); - model->setData(cmi, qobject_cast(sender())->isChecked(), Qt::UserRole + 3); - QModelIndex p = cmi.parent(), mi; - int row = 0; - qulonglong val = 0; - QList chldr; - mi = p.child(row, 1); - while (mi.isValid()) { - chldr << mi; - model->setData(mi, !mi.data(Qt::UserRole + 4).toBool(), Qt::UserRole + 4); - mi = p.child(++row, 1); - } - bool cc = cmi.data(Qt::UserRole + 3).toBool(); - qulonglong cv = cmi.data(Qt::UserRole).toULongLong(); - //qDebug() << "*****"; - if (cc && cv == 0) { - val = 0; - //qDebug() << "null" << cv; - } else { - if (!cc && cv != 0) { - //qDebug() << "uncheck" << cv; - for (int i = 0; i < chldr.size(); ++i) { - if (chldr[i] == cmi) continue; - //qDebug() << (chldr[i].data(Qt::UserRole).toULongLong() & cv); - if (chldr[i].data(Qt::UserRole).toULongLong() & cv) - model->setData(chldr[i], false, Qt::UserRole + 3); - } - } - for (int i = 0; i < chldr.size(); ++i) { - //qDebug() << chldr[i].data(Qt::UserRole + 3).toBool(); - if (chldr[i].data(Qt::UserRole + 3).toBool()) - val |= chldr[i].data(Qt::UserRole).toULongLong(); - } - } - for (int i = 0; i < chldr.size(); ++i) { - if (chldr[i] == cmi) continue; - cv = chldr[i].data(Qt::UserRole).toULongLong(); - model->setData(chldr[i], ((val & cv) == cv && cv != 0) || (val == 0 && cv == 0), Qt::UserRole + 3); - } - //qDebug() << val; - model->setData(p, val, Qt::UserRole); - model->setData(p.sibling(p.row(), 1), val, Qt::UserRole); -} - - - -PropertyEditor::PropertyEditor(QWidget * parent): QTreeWidget(parent) { - object = 0; - active_ = false; - configTree(); - connect(this, SIGNAL(itemClicked(QTreeWidgetItem * , int)), this, SLOT(itemClicked(QTreeWidgetItem * , int))); - connect(this, SIGNAL(itemChanged(QTreeWidgetItem * , int)), this, SLOT(itemChanged(QTreeWidgetItem * , int))); -} - - -PropertyEditor::~PropertyEditor() { - -} - - -void PropertyEditor::changeEvent(QEvent * e) { - QTreeWidget::changeEvent(e); - if (e->type() == QEvent::LanguageChange) { - configTree(); - return; - } -} - - -void PropertyEditor::configTree() { - setColumnCount(2); - setRootIsDecorated(false); - setColumnWidth(0, 170); - setColumnWidth(1, 10); - header()->setStretchLastSection(true); - QStringList lbls; - lbls << tr("Property") << tr("Value"); - setHeaderLabels(lbls); - setAlternatingRowColors(true); - setItemDelegateForColumn(1, new Delegate()); - -} - - -void PropertyEditor::itemClicked(QTreeWidgetItem * item, int column) { - if (column == 0) - item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); - else { - item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable); - editItem(item, 1); - } -} - - -void PropertyEditor::itemChanged(QTreeWidgetItem * item, int column) { - if (!active_) return; - if (column != 1) return; - QVariant value = item->data(1, Qt::UserRole); - if (value.canConvert()) { - value = value.value().second; - } - object->setProperty(item->text(0).toLatin1(), value); -} - - -void PropertyEditor::rebuild() { - clear(); - configTree(); - if (object == 0) return; - active_ = false; - const QMetaObject * mo = object->metaObject(); - QList mol; - while (mo != 0) { - mol.push_front(mo); - mo = mo->superClass(); - } - int ps, pe; - QTreeWidgetItem * ti, * tli, * tfi; - QVariant value; -// QWidget * pw = 0; - int chue = 0; - QColor bc; - font_b = font(); - font_b.setBold(true); - foreach (const QMetaObject * o, mol) { - ps = o->propertyOffset(); - pe = o->propertyCount();// - ps; - //qDebug() << i->className() << ps << pe; - tli = new QTreeWidgetItem(); - tli->setText(0, o->className()); - tli->setFont(0, font_b); - setItemBackColor(tli, Qt::darkGray); - setItemForeColor(tli, Qt::white); - addTopLevelItem(tli); - setFirstItemColumnSpanned(tli, true); - tli->setExpanded(true); - for (int i = ps; i < pe; ++i) { - props << o->property(i); - value = o->property(i).read(object); - ti = new QTreeWidgetItem(); - ti->setSizeHint(1, QSize(20, 20)); - bc.setHsv(chue, 60, 245 + (i % 2) * 20 - 10); - setItemBackColor(ti, bc); - ti->setText(0, o->property(i).name()); - if (props.back().isFlagType()) { - QMetaEnum menum = props.back().enumerator(); - for (int j = 0; j < menum.keyCount(); ++j) { - tfi = new QTreeWidgetItem(); - tfi->setText(0, menum.key(j)); - tfi->setData(1, Qt::UserRole, menum.value(j)); - tfi->setData(1, Qt::UserRole + 1, "__flag"); - tfi->setData(1, Qt::UserRole + 2, value.toULongLong()); - tfi->setData(1, Qt::UserRole + 3, (value.toULongLong() & menum.value(j)) > 0); - tfi->setSizeHint(1, QSize(20, 20)); - bc.setHsv(chue, 60, 245 + ((i + j + 1) % 2) * 20 - 10); - setItemBackColor(tfi, bc); - ti->addChild(tfi); - } - ti->setData(0, Qt::UserRole, value); - ti->setData(1, Qt::UserRole, value); - ti->setData(1, Qt::UserRole + 2, "__flags"); - ti->setData(0, Qt::UserRole + 1, QVariant::fromValue(props.back())); - } - else if (props.back().isEnumType()) - value.setValue(PropertyValuePair(props.back(), value)); - //ti->setText(1, value.toString()); - ti->setData(1, Qt::UserRole, value); - tli->addChild(ti); - //const_cast(indexFromItem(ti, 1)).; - //if (pw != 0) setItemWidget(ti, 1, pw); - } - chue += 60; - chue %= 360; - } - active_ = true; -} - - -void PropertyEditor::refresh() { - -} diff --git a/qglengine/widgets/propertyeditor.h b/qglengine/widgets/propertyeditor.h deleted file mode 100644 index 143e32c..0000000 --- a/qglengine/widgets/propertyeditor.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - QGL PropertyEditor - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef PROPERTYEDITOR_H -#define PROPERTYEDITOR_H - -#include -#include -#include -#include -#include -#include -#include - - -class Delegate: public QStyledItemDelegate { - Q_OBJECT -public: - Delegate(QObject * parent = 0): QStyledItemDelegate() {ab = QBrush(QImage(":/icons/alpha.png"));} - - QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const {cmi = const_cast(index); return widgetForProperty(parent, index);} - void setEditorData(QWidget * editor, const QModelIndex & index) const {setWidgetProperty(editor, index.data(Qt::UserRole));} - void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const; - void updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index) const {editor->setGeometry(option.rect);} - void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const; - -private: - QWidget * widgetForProperty(QWidget * parent, const QModelIndex & index) const; - void setWidgetProperty(QWidget * w, const QVariant & value) const; - const QVariant widgetProperty(QWidget * w) const; - QString pointString(const QPoint & p) const {return QString::number(p.x()) + " x " + QString::number(p.y());} - QString pointString(const QPointF & p) const {return QString::number(p.x()) + " x " + QString::number(p.y());} - QString rectString(const QRect & r) const {return QString::number(r.x()) + " x " + QString::number(r.y()) + " : " + - QString::number(r.width()) + " x " + QString::number(r.height());} - QString rectString(const QRectF & r) const {return QString::number(r.x()) + " x " + QString::number(r.y()) + " : " + - QString::number(r.width()) + " x " + QString::number(r.height());} - - QBrush ab; - mutable QModelIndex cmi; - -private slots: - void changed() {setModelData((QWidget * )sender(), const_cast(cmi.model()), cmi);} - void changedFlag(); - -}; - -typedef QPair PropertyValuePair; -Q_DECLARE_METATYPE (PropertyValuePair) -Q_DECLARE_METATYPE (QMetaProperty) - -class PropertyEditor: public QTreeWidget { - Q_OBJECT -public: - explicit PropertyEditor(QWidget * parent = 0); - virtual ~PropertyEditor(); - - void assignObject(QObject * o) {object = o; rebuild();} - -protected: - void changeEvent(QEvent * e); - -private: - void configTree(); - void setItemBackColor(QTreeWidgetItem * i, const QColor & c) {i->setBackgroundColor(0, c); i->setBackgroundColor(1, c);} - void setItemForeColor(QTreeWidgetItem * i, const QColor & c) {i->setForeground(0, c); i->setForeground(1, c);} - void rebuild(); - void refresh(); - - QObject * object; - QFont font_b; - QList props; - bool active_; - -private slots: - void itemClicked(QTreeWidgetItem * item, int column); - void itemChanged(QTreeWidgetItem * item, int column); - -}; - -#endif // PROPERTYEDITOR_H diff --git a/qglengine/widgets/scene_tree.cpp b/qglengine/widgets/scene_tree.cpp deleted file mode 100644 index b137d53..0000000 --- a/qglengine/widgets/scene_tree.cpp +++ /dev/null @@ -1,504 +0,0 @@ -/* - QGL SceneTree - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "scene_tree.h" -#include "ui_scene_tree.h" -#include "glcamera.h" -#include "qglview.h" -#include -#include -#include -#include - -enum Column { - cName, - cVis, - cMaterial -}; -enum ItemRole { - irObject = Qt::UserRole, - irType = Qt::UserRole + 1, -}; - -enum ObjectType { - otNode = 1, - otMesh = 2, - otLight = 4, - otCamera = 8, -}; - - -QAction * newSeparator() { - QAction * s = new QAction(); - s->setSeparator(true); - return s; -} - - -SceneTree::SceneTree(QWidget * parent): QWidget(parent) { - ui = new Ui::SceneTree(); - ui->setupUi(this); - ui->treeObjects->header()->setSectionResizeMode(cVis, QHeaderView::ResizeToContents); - ui->treeObjects->header()->setSectionsMovable(false); - ui->treeObjects->header()->swapSections(cName, cVis); - icon_empty = QIcon(":/icons/type-empty.png"); - icon_geo = QIcon(":/icons/type-geo.png"); - icon_camera = QIcon(":/icons/type-camera.png"); - icon_light = QIcon(":/icons/type-light.png"); - icon_vis[0] = QIcon(":/icons/layer-visible-off.png"); - icon_vis[1] = QIcon(":/icons/layer-visible-on.png"); - ui->treeObjects->addActions(actionsSelection()); - ui->treeObjects->addAction (newSeparator()); - ui->treeObjects->addActions(actionsAdd()); - ui->buttonFilter->addActions(QList() << ui->actionFilter_node << ui->actionFilter_mesh << ui->actionFilter_light << ui->actionFilter_camera); - view = 0; - hidden_by_filter = obj_count = 0; - block_tree = false; - connect(ui->treeObjects->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(treeObjects_selectionCnahged())); -} - - -SceneTree::~SceneTree() { - delete ui; -} - - -void SceneTree::assignQGLView(QGLView * v) { - view = v; - objectsTreeChanged(); - if (!view) return; - connect(view, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); - connect(view, SIGNAL(materialsChanged()), this, SLOT(materialsChanged())); - connect(view->scene(), SIGNAL(treeChanged()), this, SLOT(objectsTreeChanged())); - connect(view->scene(), SIGNAL(__objectDeleted(ObjectBase*)), this, SLOT(__objectDeleted(ObjectBase*))); - view->setContextActions(actionsSelection()); - checkActions(); -} - - -QList SceneTree::actionsAdd() { - QList ret; - ret << ui->actionAdd_node << ui->actionAdd_light << ui->actionAdd_camera; - return ret; -} - - -QList SceneTree::actionsSelection() { - QList ret; - ret << ui->actionFocus << newSeparator() - << ui->actionGroup << ui->actionClone << newSeparator() - << ui->actionSelect_parent << ui->actionSelect_by_mesh << ui->actionSelect_by_material << newSeparator() - << ui->actionTransfer_transform_to_children << newSeparator() - << ui->actionActive_camera << ui->actionDefault_camera << newSeparator() - << ui->actionRemove; - return ret; -} - - -void SceneTree::changeEvent(QEvent * e) { - QWidget::changeEvent(e); - if (e->type() == QEvent::LanguageChange) { - ui->retranslateUi(this); - return; - } -} - - -void SceneTree::rememberExpanded(QTreeWidgetItem * ti) { - for (int i = 0; i < ti->childCount(); ++i) { - QTreeWidgetItem * ci = ti->child(i); - if (ci->isExpanded()) - expanded_ << itemObject(ci); - rememberExpanded(ci); - } -} - - -void SceneTree::restoreExpanded(QTreeWidgetItem * ti) { - for (int i = 0; i < ti->childCount(); ++i) { - QTreeWidgetItem * ci = ti->child(i); - ci->setExpanded(expanded_.contains(itemObject(ci))); - restoreExpanded(ci); - } -} - - -void SceneTree::makeObjetTree(ObjectBase * o, QTreeWidgetItem * ti) { - ++obj_count; - for (int i = 0; i < o->childCount(); ++i) { - ObjectBase * co = o->child(i); - QTreeWidgetItem * ci = new QTreeWidgetItem(ti); - ci->setText(cName, co->name()); - ci->setCheckState(cVis, co->isVisible() ? Qt::Checked : Qt::Unchecked); - ci->setIcon(cVis, icon_vis[co->isVisible(true)]); - if (co->material()) - ci->setText(cMaterial, co->material()->name); - ci->setFlags(ci->flags() | Qt::ItemIsEditable); - ObjectType t = otNode; - switch (co->type()) { - case ObjectBase::glMesh: - if (co->mesh()) { - t = otMesh; - ci->setIcon(cName, icon_geo); - geo_items << ci; - } else { - ci->setIcon(cName, icon_empty); - } - break; - case ObjectBase::glLight: - t = otLight; - ci->setIcon(cName, icon_light); - break; - case ObjectBase::glCamera: - t = otCamera; - ci->setIcon(cName, icon_camera); - ci->setText(cVis, (co == view->camera()) ? "*" : ""); - cam_items << ci; - break; - default: break; - } - ci->setData(cName, irObject, quintptr(co)); - ci->setData(cName, irType, int(t)); - ci->setSelected(co->isSelected()); - makeObjetTree(co, ci); - } -} - - -ObjectBase * SceneTree::itemObject(QTreeWidgetItem * item) const { - if (!item) return 0; - return (ObjectBase*)(item->data(cName, irObject).toULongLong()); -} - - -int SceneTree::itemType(QTreeWidgetItem * item) const { - if (!item) return otNode; - return item->data(cName, irType).toInt(); -} - - -void SceneTree::selectionChanged() { - if (block_tree) return; - block_tree = true; - QList il = ui->treeObjects->findItems("", Qt::MatchContains | Qt::MatchRecursive); - const ObjectBase * fo = 0; - if (view->selectedObjects().size() == 1) - fo = view->selectedObject(); - foreach (QTreeWidgetItem * i, il) { - ObjectBase * o = itemObject(i); - i->setSelected(o->isSelected()); - if (fo && (fo == o)) { - ui->treeObjects->setCurrentItem(i); - } - } - block_tree = false; - checkActions(); -} - - -void SceneTree::materialsChanged() { - foreach (QTreeWidgetItem * i, geo_items) { - ObjectBase * o = itemObject(i); - if (!o) continue; - if (o->material()) - i->setText(cMaterial, o->material()->name); - } -} - - -void SceneTree::cameraChanged() { - if (!view) return; - foreach (QTreeWidgetItem * i, cam_items) { - ObjectBase * o = itemObject(i); - if (!o) continue; - i->setText(cVis, (o == view->camera()) ? "*" : ""); - } -} - - -bool SceneTree::filterTree(QTreeWidgetItem * ti, const QString & filter, int types) { - bool ret = false; - for (int i = 0; i < ti->childCount(); ++i) { - QTreeWidgetItem * ci = ti->child(i); - QString cit = ci->text(cName); - int t = itemType(ci); - if (ci->childCount() > 0) { - if (!filterTree(ci, filter, types)) { - ci->setHidden(true); - ++hidden_by_filter; - continue; - } - ci->setHidden(false); - ret = true; - } else { - bool f = false; - if (filter.isEmpty()) { - f = true; - } else { - f = f || cit.contains(filter, Qt::CaseInsensitive); - } - if ((types & t) != t) - f = false; - ci->setHidden(!f); - if (f) ret = true; - else ++hidden_by_filter; - } - } - return ret; -} - - -void SceneTree::checkActions() { - bool has_1 = false, has_m = false; - if (view) { - has_1 = !view->selectedObjects().isEmpty(); - has_m = view->selectedObjects().size() > 1; - } - ui->actionFocus ->setEnabled(has_1); - ui->actionRemove->setEnabled(has_1); - ui->actionClone ->setEnabled(has_1); - ui->actionGroup->setEnabled(has_m); - ui->actionTransfer_transform_to_children->setEnabled(has_1); - ui->actionSelect_parent->setEnabled(has_1); - ui->actionSelect_by_mesh->setEnabled(has_1); - ui->actionSelect_by_material->setEnabled(has_1); - ui->actionActive_camera->setEnabled(has_1); -} - - -void SceneTree::treeObjects_selectionCnahged() { - if (block_tree || !view) return; - block_tree = true; - view->scene()->clearSelection(); - ObjectBaseList sol; - QList til = ui->treeObjects->selectedItems(); - foreach (QTreeWidgetItem * i, til) - sol << itemObject(i); - view->scene()->selectObjects(sol); - block_tree = false; - checkActions(); -} - - -void SceneTree::filter() { - int types = 0; - if (ui->actionFilter_node ->isChecked()) types |= otNode ; - if (ui->actionFilter_mesh ->isChecked()) types |= otMesh ; - if (ui->actionFilter_light ->isChecked()) types |= otLight ; - if (ui->actionFilter_camera->isChecked()) types |= otCamera; - if (types == 0) types = 0xFF; - hidden_by_filter = 0; - filterTree(ui->treeObjects->invisibleRootItem(), ui->lineFilter->text(), types); - ui->treeObjects->invisibleRootItem()->setHidden(false); - ui->labelCounts->setText(tr("%1 objects, %2 hide by filter").arg(obj_count).arg(hidden_by_filter)); -} - - -void SceneTree::__objectDeleted(ObjectBase * o) { - for (int i = 0; i < geo_items.size(); ++i) - if (itemObject(geo_items[i]) == o) { - geo_items.removeAt(i); - --i; - } - for (int i = 0; i < cam_items.size(); ++i) - if (itemObject(cam_items[i]) == o) { - cam_items.removeAt(i); - --i; - } -} - - -void SceneTree::on_treeObjects_itemChanged(QTreeWidgetItem * item, int column) { - if (block_tree) return; - if (column == cName) { - ObjectBase * o = itemObject(item); - if (o) o->setName(item->text(cName)); - } - if (column == cVis) { - bool vis = item->checkState(cVis) == Qt::Checked; - QList til = ui->treeObjects->selectedItems(); - if (!til.contains(item)) { - til.clear(); - til << item; - } - foreach (QTreeWidgetItem * ti, til) { - //itemObject(ti)->setVisible(vis); - itemObject(ti)->setVisible(vis); - } - } -} - - -void SceneTree::on_treeObjects_itemMoved(QTreeWidgetItem * item, QTreeWidgetItem * new_parent) { - ObjectBase * co = itemObject(item); - if (!co->hasParent()) return; - //co->parent()->removeChild(co); - if (new_parent == ui->treeObjects->invisibleRootItem()) { - view->scene()->rootObject()->addChild(co); - } else { - ObjectBase * po = itemObject(new_parent); - if (po) - po->addChild(co); - } -} - - -void SceneTree::on_actionAdd_node_triggered() { - if (!view) return; - ObjectBase * no = new ObjectBase(); - view->scene()->addObject(no); - view->scene()->selectObject(no); -} - - -void SceneTree::on_actionAdd_light_triggered() { - if (!view) return; - ObjectBase * no = new Light(); - view->scene()->addObject(no); - view->scene()->selectObject(no); -} - - -void SceneTree::on_actionAdd_camera_triggered() { - if (!view) return; - ObjectBase * no = new Camera(); - view->scene()->addObject(no); - view->scene()->selectObject(no); -} - - -void SceneTree::on_actionClone_triggered() { - if (!view) return; - QList sil = ui->treeObjects->selectedItems(); - ObjectBaseList col; - foreach (QTreeWidgetItem * i, sil) { - ObjectBase * o = itemObject(i); - if (!o) continue; - ObjectBase * no = o->clone(); - o->parent()->addChild(no); - col << no; - } - view->scene()->selectObjects(col); -} - - -void SceneTree::on_actionGroup_triggered() { - if (!view) return; - ObjectBaseList sol = view->scene()->selectedObjects(true); - ObjectBase * cp = sol[0]->parent(); - ObjectBase * nr = new ObjectBase(); - cp->addChild(nr); - foreach (ObjectBase * o, sol) - nr->addChild(o); - view->scene()->selectObject(nr); -} - - -void SceneTree::on_actionTransfer_transform_to_children_triggered() { - if (!view) return; - ObjectBaseList sol = view->scene()->selectedObjects(true); - foreach (ObjectBase * o, sol) - o->transferTransformToChildren(); -} - - -void SceneTree::on_actionActive_camera_triggered() { - if (!view) return; - ObjectBase * o = view->scene()->selectedObject(); - if (!o) return; - if (o->type() != ObjectBase::glCamera) return; - view->setCamera((Camera *)o); - cameraChanged(); -} - - -void SceneTree::on_actionDefault_camera_triggered() { - if (!view) return; - view->setDefaultCamera(); - cameraChanged(); -} - - -void SceneTree::on_actionSelect_parent_triggered() { - if (!view) return; - ObjectBaseList sol = view->scene()->selectedObjects(true); - QSet nsl; - foreach (ObjectBase * o, sol) { - ObjectBase * po = o->parent(); - if (po != view->scene()->rootObject()) - o = po; - nsl << o; - } - view->scene()->selectObjects(nsl.toList()); -} - - -void SceneTree::on_actionSelect_by_mesh_triggered() { - view->scene()->selectObjectsByMesh(); -} - - -void SceneTree::on_actionSelect_by_material_triggered() { - view->scene()->selectObjectsByMaterial(); -} - - -void SceneTree::removeObjects() { - if (!view) return; - QList sil = ui->treeObjects->selectedItems(); - foreach (QTreeWidgetItem * i, sil) { - ObjectBase * o = itemObject(i); - if (o) delete o; - } - qDeleteAll(sil); -} - - -void SceneTree::focusObjects() { - if (!view) return; - if (!view->camera()) return; - Box3D bb; - ObjectBaseList ol = view->selectedObjects(); - foreach (ObjectBase * o, ol) { - o->calculateBoundingBox(); - bb |= o->boundingBox(); - } - view->focusOn(bb); -} - - -void SceneTree::objectsTreeChanged() { - int vpos = ui->treeObjects->verticalScrollBar()->value(); - expanded_.clear(); - geo_items.clear(); - cam_items.clear(); - rememberExpanded(ui->treeObjects->invisibleRootItem()); - block_tree = true; - ui->treeObjects->clear(); - block_tree = false; - if (!view) return; - block_tree = true; - obj_count = 0; - makeObjetTree(view->scene()->rootObject(), ui->treeObjects->invisibleRootItem()); - --obj_count; - restoreExpanded(ui->treeObjects->invisibleRootItem()); - block_tree = false; - filter(); - QApplication::processEvents(); - ui->treeObjects->verticalScrollBar()->setValue(vpos); -} diff --git a/qglengine/widgets/scene_tree.h b/qglengine/widgets/scene_tree.h deleted file mode 100644 index bf16a55..0000000 --- a/qglengine/widgets/scene_tree.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - QGL SceneTree - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef SCENE_TREE_H -#define SCENE_TREE_H - -#include -#include -#include "glscene.h" - -class QTreeWidgetItem; - -namespace Ui { - class SceneTree; -} - -class SceneTree: public QWidget -{ - Q_OBJECT -public: - SceneTree(QWidget * parent = 0); - ~SceneTree(); - - void assignQGLView(QGLView * v); - QList actionsAdd(); - QList actionsSelection(); - -private: - void changeEvent(QEvent * e); - void rememberExpanded(QTreeWidgetItem * ti); - void restoreExpanded(QTreeWidgetItem * ti); - void makeObjetTree(ObjectBase * o, QTreeWidgetItem * ti); - ObjectBase * itemObject(QTreeWidgetItem * item) const; - int itemType(QTreeWidgetItem * item) const; - bool filterTree(QTreeWidgetItem * ti, const QString & filter, int types); - void checkActions(); - - Ui::SceneTree * ui; - bool block_tree; - int hidden_by_filter, obj_count; - QIcon icon_empty, icon_geo, icon_camera, icon_light, icon_vis[2]; - QSet expanded_; - QList geo_items, cam_items; - QGLView * view; - -private slots: - void treeObjects_selectionCnahged(); - void on_treeObjects_itemChanged(QTreeWidgetItem * item, int column); - void on_treeObjects_itemMoved (QTreeWidgetItem * item, QTreeWidgetItem * new_parent); - - void on_actionAdd_node_triggered(); - void on_actionAdd_light_triggered(); - void on_actionAdd_camera_triggered(); - - void on_actionFocus_triggered() {focusObjects();} - void on_actionRemove_triggered() {removeObjects();} - void on_actionClone_triggered(); - void on_actionGroup_triggered(); - void on_actionTransfer_transform_to_children_triggered(); - - void on_actionActive_camera_triggered(); - void on_actionDefault_camera_triggered(); - - void on_actionSelect_parent_triggered(); - void on_actionSelect_by_mesh_triggered(); - void on_actionSelect_by_material_triggered(); - - void removeObjects(); - void focusObjects(); - void objectsTreeChanged(); - void selectionChanged(); - void materialsChanged(); - void cameraChanged(); - void filter(); - void __objectDeleted(ObjectBase * o); - -public slots: - -signals: - -private: - -}; - -#endif // SCENE_TREE_H diff --git a/qglengine/widgets/scene_tree.ui b/qglengine/widgets/scene_tree.ui deleted file mode 100644 index ec57188..0000000 --- a/qglengine/widgets/scene_tree.ui +++ /dev/null @@ -1,425 +0,0 @@ - - - SceneTree - - - - 0 - 0 - 442 - 606 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - Filter: - - - - - - - - - - - :/icons/configure.png:/icons/configure.png - - - QToolButton::InstantPopup - - - - - - - Qt::Vertical - - - - - - - Expand tree - - - - :/icons/expand.png:/icons/expand.png - - - - - - - Collapse tree - - - - :/icons/collapse.png:/icons/collapse.png - - - - - - - - - - - - - - - - Qt::ActionsContextMenu - - - QAbstractItemView::InternalMove - - - QAbstractItemView::ExtendedSelection - - - QAbstractItemView::ScrollPerPixel - - - true - - - false - - - - Name - - - - - Vis - - - - - Material - - - - - - - - - :/icons/type-camera.png:/icons/type-camera.png - - - Focus - - - - - - :/icons/edit-delete.png:/icons/edit-delete.png - - - Remove - - - - - - :/icons/edit-copy.png:/icons/edit-copy.png - - - Clone - - - - - - :/icons/group.png:/icons/group.png - - - Group - - - - - - :/icons/go-top.png:/icons/go-top.png - - - Select parent - - - - - - :/icons/type-geo.png:/icons/type-geo.png - - - Select by mesh - - - - - - :/icons/format-fill-color.png:/icons/format-fill-color.png - - - Select by material - - - - - - :/icons/add-type-empty.png:/icons/add-type-empty.png - - - Add node - - - - - - :/icons/add-type-light.png:/icons/add-type-light.png - - - Add light - - - - - - :/icons/add-type-camera.png:/icons/add-type-camera.png - - - Add camera - - - - - true - - - - :/icons/type-empty.png:/icons/type-empty.png - - - Nodes - - - - - true - - - - :/icons/type-geo.png:/icons/type-geo.png - - - Meshes - - - - - true - - - - :/icons/type-light.png:/icons/type-light.png - - - Lights - - - - - true - - - - :/icons/type-camera.png:/icons/type-camera.png - - - Cameras - - - - - Transfer transform to children - - - - - - :/icons/type-camera.png:/icons/type-camera.png - - - Active camera - - - - - - :/icons/type-camera.png:/icons/type-camera.png - - - Default camera - - - - - - CLineEdit - QLineEdit -
clineedit.h
-
- - InternalMoveTreeWidget - QTreeWidget -
treewidget_p.h
-
-
- - - - - - - - - - buttonExpand - clicked() - treeObjects - expandAll() - - - 395 - 164 - - - 299 - 359 - - - - - buttonCollapse - clicked() - treeObjects - collapseAll() - - - 427 - 164 - - - 332 - 369 - - - - - lineFilter - textChanged(QString) - SceneTree - filter() - - - 273 - 130 - - - 355 - 37 - - - - - actionFilter_camera - toggled(bool) - SceneTree - filter() - - - -1 - -1 - - - 414 - 302 - - - - - actionFilter_mesh - toggled(bool) - SceneTree - filter() - - - -1 - -1 - - - 414 - 302 - - - - - actionFilter_light - toggled(bool) - SceneTree - filter() - - - -1 - -1 - - - 414 - 302 - - - - - actionFilter_node - toggled(bool) - SceneTree - filter() - - - -1 - -1 - - - 414 - 302 - - - - - - removeObjects() - focusObjects() - filter() - -
diff --git a/qglengine/widgets/treewidget_p.h b/qglengine/widgets/treewidget_p.h deleted file mode 100644 index 18cce4b..0000000 --- a/qglengine/widgets/treewidget_p.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - QGL SceneTree - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef TREEWIDGET_H -#define TREEWIDGET_H - -#include -#include -#include -#include - -class InternalMoveTreeWidget: public QTreeWidget -{ - Q_OBJECT -public: - InternalMoveTreeWidget(QWidget * parent = 0): QTreeWidget(parent) {} - -protected: - virtual void dropEvent(QDropEvent * e) { - QList sil = selectedItems(); - if (sil.isEmpty()) return; - QTreeWidget::dropEvent(e); - foreach (QTreeWidgetItem * ti, sil) { - QTreeWidgetItem * ti_p = ti->parent(); - if (!ti_p) ti_p = invisibleRootItem(); - int ti_ppos = ti_p->indexOfChild(ti); - emit itemMoved(ti, ti_p, ti_ppos); - } - } - -signals: - void itemMoved(QTreeWidgetItem * item, QTreeWidgetItem * new_parent, int new_index); - -}; - -#endif // TREEWIDGET_H diff --git a/qglengine/widgets/view_editor.cpp b/qglengine/widgets/view_editor.cpp deleted file mode 100644 index ab48597..0000000 --- a/qglengine/widgets/view_editor.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - QGL ViewEditor - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "view_editor.h" -#include "ui_view_editor.h" -#include -#include -#include - - -ViewEditor::ViewEditor(QWidget * parent): QWidget(parent) { - ui = new Ui::ViewEditor(); - ui->setupUi(this); - view = 0; - active = true; - ui->checkCameraLight->setCheckState(Qt::PartiallyChecked); -#if QT_VERSION >= QT_VERSION_CHECK(5,12,0) - ui->spinDepthStart->setStepType(QAbstractSpinBox::AdaptiveDecimalStepType); -#endif -} - - -void ViewEditor::assignQGLView(QGLView * v) { - view = v; - if (!view) return; - active = false; - ui->spinFOV->setValue(view->FOV()); - ui->spinDepthStart->setValue(view->depthStart()); - ui->groupHoverHalo->setChecked(view->isHoverHaloEnabled()); - ui->groupSelectionHalo->setChecked(view->isSelectionHaloEnabled()); - ui->spinHoverHaloFill->setValue(view->hoverHaloFillAlpha()); - ui->spinSelectionHaloFill->setValue(view->selectionHaloFillAlpha()); - ui->colorHoverHalo->setColor(view->hoverHaloColor()); - ui->colorSelectionHalo->setColor(view->selectionHaloColor()); - ui->checkFXAA->setChecked(view->isFeatureEnabled(QGLView::qglFXAA)); - ui->checkCameraOrbit->setChecked(view->isCameraOrbit()); - ui->checkCameraLight->setCheckState((Qt::CheckState)view->cameraLightMode()); - ui->checkService->setChecked(view->isServiceMode()); - ui->lineHDR->setProperty("GLpath", view->environmentMapFile()); - ui->lineHDR->setText(QFileInfo(view->environmentMapFile()).fileName()); - active = true; -} - - -void ViewEditor::changeEvent(QEvent * e) { - QWidget::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - ui->retranslateUi(this); - break; - default: - break; - } -} - - -void ViewEditor::on_spinFOV_valueChanged(double val) { - if (!view || !active) return; - view->setFOV(val); -} - - -void ViewEditor::on_spinDepthStart_valueChanged(double val) { - if (!view || !active) return; - view->setDepthStart(val); -} - - -void ViewEditor::on_spinViewGamma_valueChanged(double val) { - if (!view || !active) return; - view->setGamma(val); -} - - -void ViewEditor::on_comboViewRenderMode_currentIndexChanged(int val) { - if (!view || !active) return; - static int modes[] = {GL_POINT, GL_LINE, GL_FILL}; - view->setRenderMode((ObjectBase::RenderMode)modes[val]); -} - - -void ViewEditor::on_groupHoverHalo_clicked(bool val) { - if (!view || !active) return; - view->setHoverHaloEnabled(val); -} - - -void ViewEditor::on_groupSelectionHalo_clicked(bool val) { - if (!view || !active) return; - view->setSelectionHaloEnabled(val); -} - - -void ViewEditor::on_spinHoverHaloFill_valueChanged(double val) { - if (!view || !active) return; - view->setHoverHaloFillAlpha(val); -} - - -void ViewEditor::on_spinSelectionHaloFill_valueChanged(double val) { - if (!view || !active) return; - view->setSelectionHaloFillAlpha(val); -} - - -void ViewEditor::on_colorHoverHalo_colorChanged(QColor color) { - if (!view || !active) return; - view->setHoverHaloColor(color); -} - - -void ViewEditor::on_colorSelectionHalo_colorChanged(QColor color) { - if (!view || !active) return; - view->setSelectionHaloColor(color); -} - - -void ViewEditor::on_checkAutoExposure_toggled(bool val) { - if (!view || !active) return; - view->setAutoExposure(val); -} - - -void ViewEditor::on_checkFXAA_clicked(bool val) { - if (!view || !active) return; - view->setFeature(QGLView::qglFXAA, val); -} - - -void ViewEditor::on_checkCameraOrbit_clicked(bool val) { - if (!view || !active) return; - view->setCameraOrbit(val); -} - - -void ViewEditor::on_checkService_clicked(bool val) { - if (!view || !active) return; - view->setServiceMode(val); -} - - -void ViewEditor::on_checkCameraLight_stateChanged(int s) { - if (!view || !active) return; - view->setCameraLightMode((QGLView::CameraLightMode)s); - -} - - -void ViewEditor::on_buttonHDRClear_clicked() { - if (!view || !active) return; - ui->lineHDR->setText(""); - ui->lineHDR->setProperty("GLpath", ""); - view->setEnvironmentMapFile(""); -} - - -void ViewEditor::on_buttonHDRSelect_clicked() { - if (!view || !active) return; - QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineHDR->property("GLpath").toString(), "Radiance HDR(*.hdr)"); - if (str.isEmpty()) return; - ui->lineHDR->setText(QFileInfo(str).fileName()); - ui->lineHDR->setProperty("GLpath", str); - view->setEnvironmentMapFile(str); -} diff --git a/qglengine/widgets/view_editor.h b/qglengine/widgets/view_editor.h deleted file mode 100644 index 405fa4b..0000000 --- a/qglengine/widgets/view_editor.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - QGL ViewEditor - Ivan Pelipenko peri4ko@yandex.ru - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef VIEW_EDITOR_H -#define VIEW_EDITOR_H - -#include -#include "qglview.h" - -namespace Ui { - class ViewEditor; -} - -class ViewEditor: public QWidget -{ - Q_OBJECT -public: - explicit ViewEditor(QWidget * parent = 0); - - void assignQGLView(QGLView * v); - -protected: - void changeEvent(QEvent * e); - - Ui::ViewEditor * ui; - QGLView * view; - bool active; - -private slots: - void on_spinFOV_valueChanged(double val); - void on_spinDepthStart_valueChanged(double val); - void on_spinViewGamma_valueChanged(double val); - void on_comboViewRenderMode_currentIndexChanged(int val); - void on_groupHoverHalo_clicked(bool val); - void on_groupSelectionHalo_clicked(bool val); - void on_spinHoverHaloFill_valueChanged(double val); - void on_spinSelectionHaloFill_valueChanged(double val); - void on_colorHoverHalo_colorChanged(QColor color); - void on_colorSelectionHalo_colorChanged(QColor color); - void on_checkAutoExposure_toggled(bool val); - void on_checkFXAA_clicked(bool val); - void on_checkCameraOrbit_clicked(bool val); - void on_checkService_clicked(bool val); - void on_checkCameraLight_stateChanged(int s); - void on_buttonHDRClear_clicked(); - void on_buttonHDRSelect_clicked(); - -signals: - -}; - -#endif // VIEW_EDITOR_H diff --git a/qglengine/widgets/view_editor.ui b/qglengine/widgets/view_editor.ui deleted file mode 100644 index 744b0a5..0000000 --- a/qglengine/widgets/view_editor.ui +++ /dev/null @@ -1,511 +0,0 @@ - - - ViewEditor - - - - 0 - 0 - 328 - 538 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Draw mode: - - - - - - - 2 - - - - Point - - - - - Wireframe - - - - - Solid - - - - - - - - Gamma: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 0.010000000000000 - - - 5.000000000000000 - - - 1.000000000000000 - - - 2 - - - - - - - Env HDR: - - - - - - - 2 - - - - - - - - - :/icons/edit-delete.png:/icons/edit-delete.png - - - - - - - - :/icons/document-open.png:/icons/document-open.png - - - - - - - - - - - - - - FXAA - - - - - - - Auto exposure - - - - - - - Service mode - - - true - - - - - - - Camera light - - - true - - - - - - - - - Camera - - - - - - - - Orbit - - - true - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 40 - 1 - - - - - - - - FOV: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 0.100000000000000 - - - 179.900000000000006 - - - 60.000000000000000 - - - - - - - - - - - Depth start: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 3 - - - 999999999.000000000000000 - - - 1.000000000000000 - - - - - - - - - - - - Hover halo - - - true - - - - - - Fill: - - - - - - - 0.000000000000000 - - - 1.000000000000000 - - - 0.300000000000000 - - - 2 - - - 0.050000000000000 - - - 0.100000000000000 - - - - - - - - 255 - 0 - 251 - - - - true - - - - - - - - - - Selection halo - - - true - - - - - - Fill: - - - - - - - 0.000000000000000 - - - 1.000000000000000 - - - 0.300000000000000 - - - 2 - - - 0.050000000000000 - - - 0.100000000000000 - - - - - - - - 0 - 143 - 239 - - - - true - - - - - - - - - - - - - 0 - 0 - - - - Fog - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - Density: - - - - - - - - - 0.000000000000000 - - - 10.000000000000000 - - - 0.000000000000000 - - - 3 - - - 0.050000000000000 - - - 0.100000000000000 - - - - - - - - 128 - 128 - 128 - - - - - - - - - - Decay: - - - - - - - 0.000000000000000 - - - 9999.000000000000000 - - - 10.000000000000000 - - - 2 - - - 0.050000000000000 - - - 0.100000000000000 - - - true - - - 9999.000000000000000 - - - - - - - - - - - - Qt::Vertical - - - - 20 - 1 - - - - - - - - - SpinSlider - QWidget -
spinslider.h
-
- - ColorButton - QPushButton -
colorbutton.h
-
-
- - - - - -
diff --git a/qglengine/widgets/widgets.qrc b/qglengine/widgets/widgets.qrc deleted file mode 100644 index c83819f..0000000 --- a/qglengine/widgets/widgets.qrc +++ /dev/null @@ -1,18 +0,0 @@ - - - ../icons/go-jump.png - ../icons/dialog-close.png - ../icons/dialog-cancel.png - ../icons/edit-clear.png - ../icons/configure.png - ../icons/document-save.png - ../icons/edit-find.png - ../icons/list-add.png - ../icons/edit-delete.png - ../icons/edit-copy.png - ../icons/edit-paste.png - ../icons/document-edit.png - ../icons/group.png - ../icons/format-fill-color.png - - diff --git a/qglview/LICENSE.txt b/qglview/LICENSE.txt deleted file mode 100644 index 0a04128..0000000 --- a/qglview/LICENSE.txt +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/qglview/icons/alpha.png b/qglview/icons/alpha.png deleted file mode 100644 index 5435669..0000000 Binary files a/qglview/icons/alpha.png and /dev/null differ diff --git a/qglview/icons/application-exit.png b/qglview/icons/application-exit.png deleted file mode 100644 index ed5f8b2..0000000 Binary files a/qglview/icons/application-exit.png and /dev/null differ diff --git a/qglview/icons/configure.png b/qglview/icons/configure.png deleted file mode 100644 index 5ce478b..0000000 Binary files a/qglview/icons/configure.png and /dev/null differ diff --git a/qglview/icons/dialog-close.png b/qglview/icons/dialog-close.png deleted file mode 100644 index 2c2f99e..0000000 Binary files a/qglview/icons/dialog-close.png and /dev/null differ diff --git a/qglview/icons/document-save.png b/qglview/icons/document-save.png deleted file mode 100644 index 8072aea..0000000 Binary files a/qglview/icons/document-save.png and /dev/null differ diff --git a/qglview/icons/edit-clear-locationbar-rtl.png b/qglview/icons/edit-clear-locationbar-rtl.png deleted file mode 100644 index 6c4b83b..0000000 Binary files a/qglview/icons/edit-clear-locationbar-rtl.png and /dev/null differ diff --git a/qglview/icons/edit-clear.png b/qglview/icons/edit-clear.png deleted file mode 100644 index 19a1665..0000000 Binary files a/qglview/icons/edit-clear.png and /dev/null differ diff --git a/qglview/icons/edit-copy.png b/qglview/icons/edit-copy.png deleted file mode 100644 index 5cdeb5f..0000000 Binary files a/qglview/icons/edit-copy.png and /dev/null differ diff --git a/qglview/icons/edit-delete.png b/qglview/icons/edit-delete.png deleted file mode 100644 index 87cd0b0..0000000 Binary files a/qglview/icons/edit-delete.png and /dev/null differ diff --git a/qglview/icons/edit-find.png b/qglview/icons/edit-find.png deleted file mode 100644 index 9a462c0..0000000 Binary files a/qglview/icons/edit-find.png and /dev/null differ diff --git a/qglview/icons/edit-guides.png b/qglview/icons/edit-guides.png deleted file mode 100644 index d264839..0000000 Binary files a/qglview/icons/edit-guides.png and /dev/null differ diff --git a/qglview/icons/edit-paste.png b/qglview/icons/edit-paste.png deleted file mode 100644 index a4e0a02..0000000 Binary files a/qglview/icons/edit-paste.png and /dev/null differ diff --git a/qglview/icons/item-add.png b/qglview/icons/item-add.png deleted file mode 100644 index 8a422c7..0000000 Binary files a/qglview/icons/item-add.png and /dev/null differ diff --git a/qglview/icons/item.png b/qglview/icons/item.png deleted file mode 100644 index 50bfddb..0000000 Binary files a/qglview/icons/item.png and /dev/null differ diff --git a/qglview/icons/list-add.png b/qglview/icons/list-add.png deleted file mode 100644 index 1e03be9..0000000 Binary files a/qglview/icons/list-add.png and /dev/null differ diff --git a/qglview/icons/node-add.png b/qglview/icons/node-add.png deleted file mode 100644 index 80b5c61..0000000 Binary files a/qglview/icons/node-add.png and /dev/null differ diff --git a/qglview/icons/node.png b/qglview/icons/node.png deleted file mode 100644 index fc8194e..0000000 Binary files a/qglview/icons/node.png and /dev/null differ diff --git a/qglview/icons/qglview.png b/qglview/icons/qglview.png deleted file mode 100644 index 21bc50b..0000000 Binary files a/qglview/icons/qglview.png and /dev/null differ diff --git a/qglview/icons/qglview.xcf b/qglview/icons/qglview.xcf deleted file mode 100644 index 50d33a6..0000000 Binary files a/qglview/icons/qglview.xcf and /dev/null differ diff --git a/qglview/icons/view-grid.png b/qglview/icons/view-grid.png deleted file mode 100644 index 0f1d70c..0000000 Binary files a/qglview/icons/view-grid.png and /dev/null differ diff --git a/qglview/icons/zoom-fit-best.png b/qglview/icons/zoom-fit-best.png deleted file mode 100644 index 07cfc98..0000000 Binary files a/qglview/icons/zoom-fit-best.png and /dev/null differ diff --git a/qglview/plugin/qglview_designerplugin.cpp b/qglview/plugin/qglview_designerplugin.cpp deleted file mode 100644 index 708776b..0000000 --- a/qglview/plugin/qglview_designerplugin.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "qglview_designerplugin.h" -#include "qglviewplugin.h" - - -QGLViewDesignerPlugin::QGLViewDesignerPlugin(QObject * parent): QObject(parent) -{ - m_widgets.append(new QGLViewPlugin(this)); -} - - -QList QGLViewDesignerPlugin::customWidgets() const { - return m_widgets; -} - diff --git a/qglview/plugin/qglview_designerplugin.h b/qglview/plugin/qglview_designerplugin.h deleted file mode 100644 index db6fc67..0000000 --- a/qglview/plugin/qglview_designerplugin.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef QGLVIEW_DESIGNERPLUGIN_H -#define QGLVIEW_DESIGNERPLUGIN_H - -#include -#include - - -class QGLViewDesignerPlugin: public QObject, public QDesignerCustomWidgetCollectionInterface -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "qad.qglview") - Q_INTERFACES(QDesignerCustomWidgetCollectionInterface) -public: - QGLViewDesignerPlugin(QObject * parent = 0); - virtual QList customWidgets() const; - -private: - QList m_widgets; - -}; - -#endif // QGLVIEW_DESIGNERPLUGIN_H diff --git a/qglview/plugin/qglviewplugin.h b/qglview/plugin/qglviewplugin.h deleted file mode 100644 index 6516afb..0000000 --- a/qglview/plugin/qglviewplugin.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef QGLVIEWPLUGIN_H -#define QGLVIEWPLUGIN_H - -#include -#include - - -class QGLViewPlugin: public QObject, public QDesignerCustomWidgetInterface -{ - Q_OBJECT - Q_INTERFACES(QDesignerCustomWidgetInterface) - -public: - explicit QGLViewPlugin(QObject * parent = 0); - - bool isContainer() const; - bool isInitialized() const; - QIcon icon() const; - QString domXml() const; - QString group() const; - QString includeFile() const; - QString name() const; - QString toolTip() const; - QString whatsThis() const; - QWidget * createWidget(QWidget * parent); - void initialize(QDesignerFormEditorInterface * core); - -private: - bool m_initialized; - -}; - -#endif //QGLVIEWPLUGIN_H diff --git a/qglview/shaders/fxaa_v3.h b/qglview/shaders/fxaa_v3.h deleted file mode 100644 index 633482e..0000000 --- a/qglview/shaders/fxaa_v3.h +++ /dev/null @@ -1,2048 +0,0 @@ -/*============================================================================ - - - NVIDIA FXAA 3.11 by TIMOTHY LOTTES - - ------------------------------------------------------------------------------- -COPYRIGHT (C) 2010, 2011 NVIDIA CORPORATION. ALL RIGHTS RESERVED. ------------------------------------------------------------------------------- -TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED -*AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA -OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR -CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR -LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, -OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE -THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - ------------------------------------------------------------------------------- - INTEGRATION CHECKLIST ------------------------------------------------------------------------------- -(1.) -In the shader source, setup defines for the desired configuration. -When providing multiple shaders (for different presets), -simply setup the defines differently in multiple files. -Example, - - #define FXAA_PC 1 - #define FXAA_HLSL_5 1 - #define FXAA_QUALITY__PRESET 12 - -Or, - - #define FXAA_360 1 - -Or, - - #define FXAA_PS3 1 - -Etc. - -(2.) -Then include this file, - - #include "Fxaa3_11.h" - -(3.) -Then call the FXAA pixel shader from within your desired shader. -Look at the FXAA Quality FxaaPixelShader() for docs on inputs. -As for FXAA 3.11 all inputs for all shaders are the same -to enable easy porting between platforms. - - return FxaaPixelShader(...); - -(4.) -Insure pass prior to FXAA outputs RGBL (see next section). -Or use, - - #define FXAA_GREEN_AS_LUMA 1 - -(5.) -Setup engine to provide the following constants -which are used in the FxaaPixelShader() inputs, - - FxaaFloat2 fxaaQualityRcpFrame, - FxaaFloat4 fxaaConsoleRcpFrameOpt, - FxaaFloat4 fxaaConsoleRcpFrameOpt2, - FxaaFloat4 fxaaConsole360RcpFrameOpt2, - FxaaFloat fxaaQualitySubpix, - FxaaFloat fxaaQualityEdgeThreshold, - FxaaFloat fxaaQualityEdgeThresholdMin, - FxaaFloat fxaaConsoleEdgeSharpness, - FxaaFloat fxaaConsoleEdgeThreshold, - FxaaFloat fxaaConsoleEdgeThresholdMin, - FxaaFloat4 fxaaConsole360ConstDir - -Look at the FXAA Quality FxaaPixelShader() for docs on inputs. - -(6.) -Have FXAA vertex shader run as a full screen triangle, -and output "pos" and "fxaaConsolePosPos" -such that inputs in the pixel shader provide, - - // {xy} = center of pixel - FxaaFloat2 pos, - - // {xy__} = upper left of pixel - // {__zw} = lower right of pixel - FxaaFloat4 fxaaConsolePosPos, - -(7.) -Insure the texture sampler(s) used by FXAA are set to bilinear filtering. - - ------------------------------------------------------------------------------- - INTEGRATION - RGBL AND COLORSPACE ------------------------------------------------------------------------------- -FXAA3 requires RGBL as input unless the following is set, - - #define FXAA_GREEN_AS_LUMA 1 - -In which case the engine uses green in place of luma, -and requires RGB input is in a non-linear colorspace. - -RGB should be LDR (low dynamic range). -Specifically do FXAA after tonemapping. - -RGB data as returned by a texture fetch can be non-linear, -or linear when FXAA_GREEN_AS_LUMA is not set. -Note an "sRGB format" texture counts as linear, -because the result of a texture fetch is linear data. -Regular "RGBA8" textures in the sRGB colorspace are non-linear. - -If FXAA_GREEN_AS_LUMA is not set, -luma must be stored in the alpha channel prior to running FXAA. -This luma should be in a perceptual space (could be gamma 2.0). -Example pass before FXAA where output is gamma 2.0 encoded, - - color.rgb = ToneMap(color.rgb); // linear color output - color.rgb = sqrt(color.rgb); // gamma 2.0 color output - return color; - -To use FXAA, - - color.rgb = ToneMap(color.rgb); // linear color output - color.rgb = sqrt(color.rgb); // gamma 2.0 color output - color.a = dot(color.rgb, FxaaFloat3(0.299, 0.587, 0.114)); // compute luma - return color; - -Another example where output is linear encoded, -say for instance writing to an sRGB formated render target, -where the render target does the conversion back to sRGB after blending, - - color.rgb = ToneMap(color.rgb); // linear color output - return color; - -To use FXAA, - - color.rgb = ToneMap(color.rgb); // linear color output - color.a = sqrt(dot(color.rgb, FxaaFloat3(0.299, 0.587, 0.114))); // compute luma - return color; - -Getting luma correct is required for the algorithm to work correctly. - - ------------------------------------------------------------------------------- - BEING LINEARLY CORRECT? ------------------------------------------------------------------------------- -Applying FXAA to a framebuffer with linear RGB color will look worse. -This is very counter intuitive, but happends to be true in this case. -The reason is because dithering artifacts will be more visiable -in a linear colorspace. - - ------------------------------------------------------------------------------- - COMPLEX INTEGRATION ------------------------------------------------------------------------------- -Q. What if the engine is blending into RGB before wanting to run FXAA? - -A. In the last opaque pass prior to FXAA, - have the pass write out luma into alpha. - Then blend into RGB only. - FXAA should be able to run ok - assuming the blending pass did not any add aliasing. - This should be the common case for particles and common blending passes. - -A. Or use FXAA_GREEN_AS_LUMA. - -============================================================================*/ - -/*============================================================================ - - INTEGRATION KNOBS - -============================================================================*/ -// -// FXAA_PS3 and FXAA_360 choose the console algorithm (FXAA3 CONSOLE). -// FXAA_360_OPT is a prototype for the new optimized 360 version. -// -// 1 = Use API. -// 0 = Don't use API. -// -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_PS3 - #define FXAA_PS3 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_360 - #define FXAA_360 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_360_OPT - #define FXAA_360_OPT 0 -#endif -/*==========================================================================*/ -#ifndef FXAA_PC - // - // FXAA Quality - // The high quality PC algorithm. - // - #define FXAA_PC 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_PC_CONSOLE - // - // The console algorithm for PC is included - // for developers targeting really low spec machines. - // Likely better to just run FXAA_PC, and use a really low preset. - // - #define FXAA_PC_CONSOLE 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_GLSL_120 - #define FXAA_GLSL_120 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_GLSL_130 - #define FXAA_GLSL_130 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_HLSL_3 - #define FXAA_HLSL_3 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_HLSL_4 - #define FXAA_HLSL_4 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_HLSL_5 - #define FXAA_HLSL_5 0 -#endif -/*==========================================================================*/ -#ifndef FXAA_GREEN_AS_LUMA - // - // For those using non-linear color, - // and either not able to get luma in alpha, or not wanting to, - // this enables FXAA to run using green as a proxy for luma. - // So with this enabled, no need to pack luma in alpha. - // - // This will turn off AA on anything which lacks some amount of green. - // Pure red and blue or combination of only R and B, will get no AA. - // - // Might want to lower the settings for both, - // fxaaConsoleEdgeThresholdMin - // fxaaQualityEdgeThresholdMin - // In order to insure AA does not get turned off on colors - // which contain a minor amount of green. - // - // 1 = On. - // 0 = Off. - // - #define FXAA_GREEN_AS_LUMA 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_EARLY_EXIT - // - // Controls algorithm's early exit path. - // On PS3 turning this ON adds 2 cycles to the shader. - // On 360 turning this OFF adds 10ths of a millisecond to the shader. - // Turning this off on console will result in a more blurry image. - // So this defaults to on. - // - // 1 = On. - // 0 = Off. - // - #define FXAA_EARLY_EXIT 1 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_DISCARD - // - // Only valid for PC OpenGL currently. - // Probably will not work when FXAA_GREEN_AS_LUMA = 1. - // - // 1 = Use discard on pixels which don't need AA. - // For APIs which enable concurrent TEX+ROP from same surface. - // 0 = Return unchanged color on pixels which don't need AA. - // - #define FXAA_DISCARD 0 -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_FAST_PIXEL_OFFSET - // - // Used for GLSL 120 only. - // - // 1 = GL API supports fast pixel offsets - // 0 = do not use fast pixel offsets - // - #ifdef GL_EXT_gpu_shader4 - #define FXAA_FAST_PIXEL_OFFSET 1 - #endif - #ifdef GL_NV_gpu_shader5 - #define FXAA_FAST_PIXEL_OFFSET 1 - #endif - #ifdef GL_ARB_gpu_shader5 - #define FXAA_FAST_PIXEL_OFFSET 1 - #endif - #ifndef FXAA_FAST_PIXEL_OFFSET - #define FXAA_FAST_PIXEL_OFFSET 0 - #endif -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_GATHER4_ALPHA - // - // 1 = API supports gather4 on alpha channel. - // 0 = API does not support gather4 on alpha channel. - // - #if (FXAA_HLSL_5 == 1) - #define FXAA_GATHER4_ALPHA 1 - #endif - #ifdef GL_ARB_gpu_shader5 - #define FXAA_GATHER4_ALPHA 1 - #endif - #ifdef GL_NV_gpu_shader5 - #define FXAA_GATHER4_ALPHA 1 - #endif - #ifndef FXAA_GATHER4_ALPHA - #define FXAA_GATHER4_ALPHA 0 - #endif -#endif - -/*============================================================================ - FXAA CONSOLE PS3 - TUNING KNOBS -============================================================================*/ -#ifndef FXAA_CONSOLE__PS3_EDGE_SHARPNESS - // - // Consoles the sharpness of edges on PS3 only. - // Non-PS3 tuning is done with shader input. - // - // Due to the PS3 being ALU bound, - // there are only two safe values here: 4 and 8. - // These options use the shaders ability to a free *|/ by 2|4|8. - // - // 8.0 is sharper - // 4.0 is softer - // 2.0 is really soft (good for vector graphics inputs) - // - #if 1 - #define FXAA_CONSOLE__PS3_EDGE_SHARPNESS 8.0 - #endif - #if 0 - #define FXAA_CONSOLE__PS3_EDGE_SHARPNESS 4.0 - #endif - #if 0 - #define FXAA_CONSOLE__PS3_EDGE_SHARPNESS 2.0 - #endif -#endif -/*--------------------------------------------------------------------------*/ -#ifndef FXAA_CONSOLE__PS3_EDGE_THRESHOLD - // - // Only effects PS3. - // Non-PS3 tuning is done with shader input. - // - // The minimum amount of local contrast required to apply algorithm. - // The console setting has a different mapping than the quality setting. - // - // This only applies when FXAA_EARLY_EXIT is 1. - // - // Due to the PS3 being ALU bound, - // there are only two safe values here: 0.25 and 0.125. - // These options use the shaders ability to a free *|/ by 2|4|8. - // - // 0.125 leaves less aliasing, but is softer - // 0.25 leaves more aliasing, and is sharper - // - #if 1 - #define FXAA_CONSOLE__PS3_EDGE_THRESHOLD 0.125 - #else - #define FXAA_CONSOLE__PS3_EDGE_THRESHOLD 0.25 - #endif -#endif - -/*============================================================================ - FXAA QUALITY - TUNING KNOBS ------------------------------------------------------------------------------- -NOTE the other tuning knobs are now in the shader function inputs! -============================================================================*/ -#ifndef FXAA_QUALITY__PRESET - // - // Choose the quality preset. - // This needs to be compiled into the shader as it effects code. - // Best option to include multiple presets is to - // in each shader define the preset, then include this file. - // - // OPTIONS - // ----------------------------------------------------------------------- - // 10 to 15 - default medium dither (10=fastest, 15=highest quality) - // 20 to 29 - less dither, more expensive (20=fastest, 29=highest quality) - // 39 - no dither, very expensive - // - // NOTES - // ----------------------------------------------------------------------- - // 12 = slightly faster then FXAA 3.9 and higher edge quality (default) - // 13 = about same speed as FXAA 3.9 and better than 12 - // 23 = closest to FXAA 3.9 visually and performance wise - // _ = the lowest digit is directly related to performance - // _ = the highest digit is directly related to style - // - #define FXAA_QUALITY__PRESET 12 -#endif - - -/*============================================================================ - - FXAA QUALITY - PRESETS - -============================================================================*/ - -/*============================================================================ - FXAA QUALITY - MEDIUM DITHER PRESETS -============================================================================*/ -#if (FXAA_QUALITY__PRESET == 10) - #define FXAA_QUALITY__PS 3 - #define FXAA_QUALITY__P0 1.5 - #define FXAA_QUALITY__P1 3.0 - #define FXAA_QUALITY__P2 12.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 11) - #define FXAA_QUALITY__PS 4 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 3.0 - #define FXAA_QUALITY__P3 12.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 12) - #define FXAA_QUALITY__PS 5 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 4.0 - #define FXAA_QUALITY__P4 12.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 13) - #define FXAA_QUALITY__PS 6 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 4.0 - #define FXAA_QUALITY__P5 12.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 14) - #define FXAA_QUALITY__PS 7 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 4.0 - #define FXAA_QUALITY__P6 12.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 15) - #define FXAA_QUALITY__PS 8 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 2.0 - #define FXAA_QUALITY__P6 4.0 - #define FXAA_QUALITY__P7 12.0 -#endif - -/*============================================================================ - FXAA QUALITY - LOW DITHER PRESETS -============================================================================*/ -#if (FXAA_QUALITY__PRESET == 20) - #define FXAA_QUALITY__PS 3 - #define FXAA_QUALITY__P0 1.5 - #define FXAA_QUALITY__P1 2.0 - #define FXAA_QUALITY__P2 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 21) - #define FXAA_QUALITY__PS 4 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 22) - #define FXAA_QUALITY__PS 5 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 23) - #define FXAA_QUALITY__PS 6 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 24) - #define FXAA_QUALITY__PS 7 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 3.0 - #define FXAA_QUALITY__P6 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 25) - #define FXAA_QUALITY__PS 8 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 2.0 - #define FXAA_QUALITY__P6 4.0 - #define FXAA_QUALITY__P7 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 26) - #define FXAA_QUALITY__PS 9 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 2.0 - #define FXAA_QUALITY__P6 2.0 - #define FXAA_QUALITY__P7 4.0 - #define FXAA_QUALITY__P8 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 27) - #define FXAA_QUALITY__PS 10 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 2.0 - #define FXAA_QUALITY__P6 2.0 - #define FXAA_QUALITY__P7 2.0 - #define FXAA_QUALITY__P8 4.0 - #define FXAA_QUALITY__P9 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 28) - #define FXAA_QUALITY__PS 11 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 2.0 - #define FXAA_QUALITY__P6 2.0 - #define FXAA_QUALITY__P7 2.0 - #define FXAA_QUALITY__P8 2.0 - #define FXAA_QUALITY__P9 4.0 - #define FXAA_QUALITY__P10 8.0 -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_QUALITY__PRESET == 29) - #define FXAA_QUALITY__PS 12 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.5 - #define FXAA_QUALITY__P2 2.0 - #define FXAA_QUALITY__P3 2.0 - #define FXAA_QUALITY__P4 2.0 - #define FXAA_QUALITY__P5 2.0 - #define FXAA_QUALITY__P6 2.0 - #define FXAA_QUALITY__P7 2.0 - #define FXAA_QUALITY__P8 2.0 - #define FXAA_QUALITY__P9 2.0 - #define FXAA_QUALITY__P10 4.0 - #define FXAA_QUALITY__P11 8.0 -#endif - -/*============================================================================ - FXAA QUALITY - EXTREME QUALITY -============================================================================*/ -#if (FXAA_QUALITY__PRESET == 39) - #define FXAA_QUALITY__PS 12 - #define FXAA_QUALITY__P0 1.0 - #define FXAA_QUALITY__P1 1.0 - #define FXAA_QUALITY__P2 1.0 - #define FXAA_QUALITY__P3 1.0 - #define FXAA_QUALITY__P4 1.0 - #define FXAA_QUALITY__P5 1.5 - #define FXAA_QUALITY__P6 2.0 - #define FXAA_QUALITY__P7 2.0 - #define FXAA_QUALITY__P8 2.0 - #define FXAA_QUALITY__P9 2.0 - #define FXAA_QUALITY__P10 4.0 - #define FXAA_QUALITY__P11 8.0 -#endif - - - -/*============================================================================ - - API PORTING - -============================================================================*/ -#if (FXAA_GLSL_120 == 1) || (FXAA_GLSL_130 == 1) - #define FxaaBool bool - #define FxaaDiscard discard - #define FxaaFloat float - #define FxaaFloat2 vec2 - #define FxaaFloat3 vec3 - #define FxaaFloat4 vec4 - #define FxaaHalf float - #define FxaaHalf2 vec2 - #define FxaaHalf3 vec3 - #define FxaaHalf4 vec4 - #define FxaaInt2 ivec2 - #define FxaaSat(x) clamp(x, 0.0, 1.0) - #define FxaaTex sampler2D -#else - #define FxaaBool bool - #define FxaaDiscard clip(-1) - #define FxaaFloat float - #define FxaaFloat2 float2 - #define FxaaFloat3 float3 - #define FxaaFloat4 float4 - #define FxaaHalf half - #define FxaaHalf2 half2 - #define FxaaHalf3 half3 - #define FxaaHalf4 half4 - #define FxaaSat(x) saturate(x) -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_GLSL_120 == 1) - // Requires, - // #version 120 - // And at least, - // #extension GL_EXT_gpu_shader4 : enable - // (or set FXAA_FAST_PIXEL_OFFSET 1 to work like DX9) - #define FxaaTexTop(t, p) texture2DLod(t, p, 0.0) - #if (FXAA_FAST_PIXEL_OFFSET == 1) - #define FxaaTexOff(t, p, o, r) texture2DLodOffset(t, p, 0.0, o) - #else - #define FxaaTexOff(t, p, o, r) texture2DLod(t, p + (o * r), 0.0) - #endif - #if (FXAA_GATHER4_ALPHA == 1) - // use #extension GL_ARB_gpu_shader5 : enable - #define FxaaTexAlpha4(t, p) textureGather(t, p, 3) - #define FxaaTexOffAlpha4(t, p, o) textureGatherOffset(t, p, o, 3) - #define FxaaTexGreen4(t, p) textureGather(t, p, 1) - #define FxaaTexOffGreen4(t, p, o) textureGatherOffset(t, p, o, 1) - #endif -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_GLSL_130 == 1) - // Requires "#version 130" or better - #define FxaaTexTop(t, p) textureLod(t, p, 0.0) - #define FxaaTexOff(t, p, o, r) textureLodOffset(t, p, 0.0, o) - #if (FXAA_GATHER4_ALPHA == 1) - // use #extension GL_ARB_gpu_shader5 : enable - #define FxaaTexAlpha4(t, p) textureGather(t, p, 3) - #define FxaaTexOffAlpha4(t, p, o) textureGatherOffset(t, p, o, 3) - #define FxaaTexGreen4(t, p) textureGather(t, p, 1) - #define FxaaTexOffGreen4(t, p, o) textureGatherOffset(t, p, o, 1) - #endif -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_HLSL_3 == 1) || (FXAA_360 == 1) || (FXAA_PS3 == 1) - #define FxaaInt2 float2 - #define FxaaTex sampler2D - #define FxaaTexTop(t, p) tex2Dlod(t, float4(p, 0.0, 0.0)) - #define FxaaTexOff(t, p, o, r) tex2Dlod(t, float4(p + (o * r), 0, 0)) -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_HLSL_4 == 1) - #define FxaaInt2 int2 - struct FxaaTex { SamplerState smpl; Texture2D tex; }; - #define FxaaTexTop(t, p) t.tex.SampleLevel(t.smpl, p, 0.0) - #define FxaaTexOff(t, p, o, r) t.tex.SampleLevel(t.smpl, p, 0.0, o) -#endif -/*--------------------------------------------------------------------------*/ -#if (FXAA_HLSL_5 == 1) - #define FxaaInt2 int2 - struct FxaaTex { SamplerState smpl; Texture2D tex; }; - #define FxaaTexTop(t, p) t.tex.SampleLevel(t.smpl, p, 0.0) - #define FxaaTexOff(t, p, o, r) t.tex.SampleLevel(t.smpl, p, 0.0, o) - #define FxaaTexAlpha4(t, p) t.tex.GatherAlpha(t.smpl, p) - #define FxaaTexOffAlpha4(t, p, o) t.tex.GatherAlpha(t.smpl, p, o) - #define FxaaTexGreen4(t, p) t.tex.GatherGreen(t.smpl, p) - #define FxaaTexOffGreen4(t, p, o) t.tex.GatherGreen(t.smpl, p, o) -#endif - - -/*============================================================================ - GREEN AS LUMA OPTION SUPPORT FUNCTION -============================================================================*/ -#if (FXAA_GREEN_AS_LUMA == 0) - //FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return rgba.w; } - FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return dot(rgba.rgb, FxaaFloat3(0.299, 0.587, 0.114)); } -#else - FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return rgba.y; } -#endif - - - - -/*============================================================================ - - FXAA3 QUALITY - PC - -============================================================================*/ -#if (FXAA_PC == 1) -/*--------------------------------------------------------------------------*/ -FxaaFloat4 FxaaPixelShader( - // - // Use noperspective interpolation here (turn off perspective interpolation). - // {xy} = center of pixel - FxaaFloat2 pos, - // - // Used only for FXAA Console, and not used on the 360 version. - // Use noperspective interpolation here (turn off perspective interpolation). - // {xy__} = upper left of pixel - // {__zw} = lower right of pixel - FxaaFloat4 fxaaConsolePosPos, - // - // Input color texture. - // {rgb_} = color in linear or perceptual color space - // if (FXAA_GREEN_AS_LUMA == 0) - // {___a} = luma in perceptual color space (not linear) - FxaaTex tex, - // - // Only used on the optimized 360 version of FXAA Console. - // For everything but 360, just use the same input here as for "tex". - // For 360, same texture, just alias with a 2nd sampler. - // This sampler needs to have an exponent bias of -1. - FxaaTex fxaaConsole360TexExpBiasNegOne, - // - // Only used on the optimized 360 version of FXAA Console. - // For everything but 360, just use the same input here as for "tex". - // For 360, same texture, just alias with a 3nd sampler. - // This sampler needs to have an exponent bias of -2. - FxaaTex fxaaConsole360TexExpBiasNegTwo, - // - // Only used on FXAA Quality. - // This must be from a constant/uniform. - // {x_} = 1.0/screenWidthInPixels - // {_y} = 1.0/screenHeightInPixels - FxaaFloat2 fxaaQualityRcpFrame, - // - // Only used on FXAA Console. - // This must be from a constant/uniform. - // This effects sub-pixel AA quality and inversely sharpness. - // Where N ranges between, - // N = 0.50 (default) - // N = 0.33 (sharper) - // {x___} = -N/screenWidthInPixels - // {_y__} = -N/screenHeightInPixels - // {__z_} = N/screenWidthInPixels - // {___w} = N/screenHeightInPixels - FxaaFloat4 fxaaConsoleRcpFrameOpt, - // - // Only used on FXAA Console. - // Not used on 360, but used on PS3 and PC. - // This must be from a constant/uniform. - // {x___} = -2.0/screenWidthInPixels - // {_y__} = -2.0/screenHeightInPixels - // {__z_} = 2.0/screenWidthInPixels - // {___w} = 2.0/screenHeightInPixels - FxaaFloat4 fxaaConsoleRcpFrameOpt2, - // - // Only used on FXAA Console. - // Only used on 360 in place of fxaaConsoleRcpFrameOpt2. - // This must be from a constant/uniform. - // {x___} = 8.0/screenWidthInPixels - // {_y__} = 8.0/screenHeightInPixels - // {__z_} = -4.0/screenWidthInPixels - // {___w} = -4.0/screenHeightInPixels - FxaaFloat4 fxaaConsole360RcpFrameOpt2, - // - // Only used on FXAA Quality. - // This used to be the FXAA_QUALITY__SUBPIX define. - // It is here now to allow easier tuning. - // Choose the amount of sub-pixel aliasing removal. - // This can effect sharpness. - // 1.00 - upper limit (softer) - // 0.75 - default amount of filtering - // 0.50 - lower limit (sharper, less sub-pixel aliasing removal) - // 0.25 - almost off - // 0.00 - completely off - FxaaFloat fxaaQualitySubpix, - // - // Only used on FXAA Quality. - // This used to be the FXAA_QUALITY__EDGE_THRESHOLD define. - // It is here now to allow easier tuning. - // The minimum amount of local contrast required to apply algorithm. - // 0.333 - too little (faster) - // 0.250 - low quality - // 0.166 - default - // 0.125 - high quality - // 0.063 - overkill (slower) - FxaaFloat fxaaQualityEdgeThreshold, - // - // Only used on FXAA Quality. - // This used to be the FXAA_QUALITY__EDGE_THRESHOLD_MIN define. - // It is here now to allow easier tuning. - // Trims the algorithm from processing darks. - // 0.0833 - upper limit (default, the start of visible unfiltered edges) - // 0.0625 - high quality (faster) - // 0.0312 - visible limit (slower) - // Special notes when using FXAA_GREEN_AS_LUMA, - // Likely want to set this to zero. - // As colors that are mostly not-green - // will appear very dark in the green channel! - // Tune by looking at mostly non-green content, - // then start at zero and increase until aliasing is a problem. - FxaaFloat fxaaQualityEdgeThresholdMin, - // - // Only used on FXAA Console. - // This used to be the FXAA_CONSOLE__EDGE_SHARPNESS define. - // It is here now to allow easier tuning. - // This does not effect PS3, as this needs to be compiled in. - // Use FXAA_CONSOLE__PS3_EDGE_SHARPNESS for PS3. - // Due to the PS3 being ALU bound, - // there are only three safe values here: 2 and 4 and 8. - // These options use the shaders ability to a free *|/ by 2|4|8. - // For all other platforms can be a non-power of two. - // 8.0 is sharper (default!!!) - // 4.0 is softer - // 2.0 is really soft (good only for vector graphics inputs) - FxaaFloat fxaaConsoleEdgeSharpness, - // - // Only used on FXAA Console. - // This used to be the FXAA_CONSOLE__EDGE_THRESHOLD define. - // It is here now to allow easier tuning. - // This does not effect PS3, as this needs to be compiled in. - // Use FXAA_CONSOLE__PS3_EDGE_THRESHOLD for PS3. - // Due to the PS3 being ALU bound, - // there are only two safe values here: 1/4 and 1/8. - // These options use the shaders ability to a free *|/ by 2|4|8. - // The console setting has a different mapping than the quality setting. - // Other platforms can use other values. - // 0.125 leaves less aliasing, but is softer (default!!!) - // 0.25 leaves more aliasing, and is sharper - FxaaFloat fxaaConsoleEdgeThreshold, - // - // Only used on FXAA Console. - // This used to be the FXAA_CONSOLE__EDGE_THRESHOLD_MIN define. - // It is here now to allow easier tuning. - // Trims the algorithm from processing darks. - // The console setting has a different mapping than the quality setting. - // This only applies when FXAA_EARLY_EXIT is 1. - // This does not apply to PS3, - // PS3 was simplified to avoid more shader instructions. - // 0.06 - faster but more aliasing in darks - // 0.05 - default - // 0.04 - slower and less aliasing in darks - // Special notes when using FXAA_GREEN_AS_LUMA, - // Likely want to set this to zero. - // As colors that are mostly not-green - // will appear very dark in the green channel! - // Tune by looking at mostly non-green content, - // then start at zero and increase until aliasing is a problem. - FxaaFloat fxaaConsoleEdgeThresholdMin, - // - // Extra constants for 360 FXAA Console only. - // Use zeros or anything else for other platforms. - // These must be in physical constant registers and NOT immedates. - // Immedates will result in compiler un-optimizing. - // {xyzw} = float4(1.0, -1.0, 0.25, -0.25) - FxaaFloat4 fxaaConsole360ConstDir -) { -/*--------------------------------------------------------------------------*/ - FxaaFloat2 posM; - posM.x = pos.x; - posM.y = pos.y; - #if (FXAA_GATHER4_ALPHA == 1) - #if (FXAA_DISCARD == 0) - FxaaFloat4 rgbyM = FxaaTexTop(tex, posM); - #if (FXAA_GREEN_AS_LUMA == 0) - #define lumaM rgbyM.w - #else - #define lumaM rgbyM.y - #endif - #endif - #if (FXAA_GREEN_AS_LUMA == 0) - FxaaFloat4 luma4A = FxaaTexAlpha4(tex, posM); - FxaaFloat4 luma4B = FxaaTexOffAlpha4(tex, posM, FxaaInt2(-1, -1)); - #else - FxaaFloat4 luma4A = FxaaTexGreen4(tex, posM); - FxaaFloat4 luma4B = FxaaTexOffGreen4(tex, posM, FxaaInt2(-1, -1)); - #endif - #if (FXAA_DISCARD == 1) - #define lumaM luma4A.w - #endif - #define lumaE luma4A.z - #define lumaS luma4A.x - #define lumaSE luma4A.y - #define lumaNW luma4B.w - #define lumaN luma4B.z - #define lumaW luma4B.x - #else - FxaaFloat4 rgbyM = FxaaTexTop(tex, posM); - #if (FXAA_GREEN_AS_LUMA == 0) - #define lumaM rgbyM.w - #else - #define lumaM rgbyM.y - #endif - FxaaFloat lumaS = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 0, 1), fxaaQualityRcpFrame.xy)); - FxaaFloat lumaE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1, 0), fxaaQualityRcpFrame.xy)); - FxaaFloat lumaN = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 0,-1), fxaaQualityRcpFrame.xy)); - FxaaFloat lumaW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 0), fxaaQualityRcpFrame.xy)); - #endif -/*--------------------------------------------------------------------------*/ - FxaaFloat maxSM = max(lumaS, lumaM); - FxaaFloat minSM = min(lumaS, lumaM); - FxaaFloat maxESM = max(lumaE, maxSM); - FxaaFloat minESM = min(lumaE, minSM); - FxaaFloat maxWN = max(lumaN, lumaW); - FxaaFloat minWN = min(lumaN, lumaW); - FxaaFloat rangeMax = max(maxWN, maxESM); - FxaaFloat rangeMin = min(minWN, minESM); - FxaaFloat rangeMaxScaled = rangeMax * fxaaQualityEdgeThreshold; - FxaaFloat range = rangeMax - rangeMin; - FxaaFloat rangeMaxClamped = max(fxaaQualityEdgeThresholdMin, rangeMaxScaled); - FxaaBool earlyExit = range < rangeMaxClamped; -/*--------------------------------------------------------------------------*/ - if(earlyExit) - #if (FXAA_DISCARD == 1) - FxaaDiscard; - #else - return rgbyM; - #endif -/*--------------------------------------------------------------------------*/ - #if (FXAA_GATHER4_ALPHA == 0) - FxaaFloat lumaNW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1,-1), fxaaQualityRcpFrame.xy)); - FxaaFloat lumaSE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1, 1), fxaaQualityRcpFrame.xy)); - FxaaFloat lumaNE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1,-1), fxaaQualityRcpFrame.xy)); - FxaaFloat lumaSW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 1), fxaaQualityRcpFrame.xy)); - #else - FxaaFloat lumaNE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(1, -1), fxaaQualityRcpFrame.xy)); - FxaaFloat lumaSW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 1), fxaaQualityRcpFrame.xy)); - #endif -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaNS = lumaN + lumaS; - FxaaFloat lumaWE = lumaW + lumaE; - FxaaFloat subpixRcpRange = 1.0/range; - FxaaFloat subpixNSWE = lumaNS + lumaWE; - FxaaFloat edgeHorz1 = (-2.0 * lumaM) + lumaNS; - FxaaFloat edgeVert1 = (-2.0 * lumaM) + lumaWE; -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaNESE = lumaNE + lumaSE; - FxaaFloat lumaNWNE = lumaNW + lumaNE; - FxaaFloat edgeHorz2 = (-2.0 * lumaE) + lumaNESE; - FxaaFloat edgeVert2 = (-2.0 * lumaN) + lumaNWNE; -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaNWSW = lumaNW + lumaSW; - FxaaFloat lumaSWSE = lumaSW + lumaSE; - FxaaFloat edgeHorz4 = (abs(edgeHorz1) * 2.0) + abs(edgeHorz2); - FxaaFloat edgeVert4 = (abs(edgeVert1) * 2.0) + abs(edgeVert2); - FxaaFloat edgeHorz3 = (-2.0 * lumaW) + lumaNWSW; - FxaaFloat edgeVert3 = (-2.0 * lumaS) + lumaSWSE; - FxaaFloat edgeHorz = abs(edgeHorz3) + edgeHorz4; - FxaaFloat edgeVert = abs(edgeVert3) + edgeVert4; -/*--------------------------------------------------------------------------*/ - FxaaFloat subpixNWSWNESE = lumaNWSW + lumaNESE; - FxaaFloat lengthSign = fxaaQualityRcpFrame.x; - FxaaBool horzSpan = edgeHorz >= edgeVert; - FxaaFloat subpixA = subpixNSWE * 2.0 + subpixNWSWNESE; -/*--------------------------------------------------------------------------*/ - if(!horzSpan) lumaN = lumaW; - if(!horzSpan) lumaS = lumaE; - if(horzSpan) lengthSign = fxaaQualityRcpFrame.y; - FxaaFloat subpixB = (subpixA * (1.0/12.0)) - lumaM; -/*--------------------------------------------------------------------------*/ - FxaaFloat gradientN = lumaN - lumaM; - FxaaFloat gradientS = lumaS - lumaM; - FxaaFloat lumaNN = lumaN + lumaM; - FxaaFloat lumaSS = lumaS + lumaM; - FxaaBool pairN = abs(gradientN) >= abs(gradientS); - FxaaFloat gradient = max(abs(gradientN), abs(gradientS)); - if(pairN) lengthSign = -lengthSign; - FxaaFloat subpixC = FxaaSat(abs(subpixB) * subpixRcpRange); -/*--------------------------------------------------------------------------*/ - FxaaFloat2 posB; - posB.x = posM.x; - posB.y = posM.y; - FxaaFloat2 offNP; - offNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x; - offNP.y = ( horzSpan) ? 0.0 : fxaaQualityRcpFrame.y; - if(!horzSpan) posB.x += lengthSign * 0.5; - if( horzSpan) posB.y += lengthSign * 0.5; -/*--------------------------------------------------------------------------*/ - FxaaFloat2 posN; - posN.x = posB.x - offNP.x * FXAA_QUALITY__P0; - posN.y = posB.y - offNP.y * FXAA_QUALITY__P0; - FxaaFloat2 posP; - posP.x = posB.x + offNP.x * FXAA_QUALITY__P0; - posP.y = posB.y + offNP.y * FXAA_QUALITY__P0; - FxaaFloat subpixD = ((-2.0)*subpixC) + 3.0; - FxaaFloat lumaEndN = FxaaLuma(FxaaTexTop(tex, posN)); - FxaaFloat subpixE = subpixC * subpixC; - FxaaFloat lumaEndP = FxaaLuma(FxaaTexTop(tex, posP)); -/*--------------------------------------------------------------------------*/ - if(!pairN) lumaNN = lumaSS; - FxaaFloat gradientScaled = gradient * 1.0/4.0; - FxaaFloat lumaMM = lumaM - lumaNN * 0.5; - FxaaFloat subpixF = subpixD * subpixE; - FxaaBool lumaMLTZero = lumaMM < 0.0; -/*--------------------------------------------------------------------------*/ - lumaEndN -= lumaNN * 0.5; - lumaEndP -= lumaNN * 0.5; - FxaaBool doneN = abs(lumaEndN) >= gradientScaled; - FxaaBool doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P1; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P1; - FxaaBool doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P1; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P1; -/*--------------------------------------------------------------------------*/ - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P2; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P2; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P2; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P2; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 3) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P3; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P3; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P3; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P3; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 4) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P4; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P4; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P4; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P4; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 5) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P5; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P5; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P5; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P5; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 6) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P6; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P6; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P6; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P6; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 7) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P7; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P7; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P7; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P7; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 8) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P8; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P8; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P8; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P8; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 9) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P9; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P9; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P9; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P9; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 10) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P10; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P10; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P10; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P10; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 11) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P11; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P11; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P11; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P11; -/*--------------------------------------------------------------------------*/ - #if (FXAA_QUALITY__PS > 12) - if(doneNP) { - if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); - if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); - if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; - if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; - doneN = abs(lumaEndN) >= gradientScaled; - doneP = abs(lumaEndP) >= gradientScaled; - if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P12; - if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P12; - doneNP = (!doneN) || (!doneP); - if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P12; - if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P12; -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } - #endif -/*--------------------------------------------------------------------------*/ - } -/*--------------------------------------------------------------------------*/ - FxaaFloat dstN = posM.x - posN.x; - FxaaFloat dstP = posP.x - posM.x; - if(!horzSpan) dstN = posM.y - posN.y; - if(!horzSpan) dstP = posP.y - posM.y; -/*--------------------------------------------------------------------------*/ - FxaaBool goodSpanN = (lumaEndN < 0.0) != lumaMLTZero; - FxaaFloat spanLength = (dstP + dstN); - FxaaBool goodSpanP = (lumaEndP < 0.0) != lumaMLTZero; - FxaaFloat spanLengthRcp = 1.0/spanLength; -/*--------------------------------------------------------------------------*/ - FxaaBool directionN = dstN < dstP; - FxaaFloat dst = min(dstN, dstP); - FxaaBool goodSpan = directionN ? goodSpanN : goodSpanP; - FxaaFloat subpixG = subpixF * subpixF; - FxaaFloat pixelOffset = (dst * (-spanLengthRcp)) + 0.5; - FxaaFloat subpixH = subpixG * fxaaQualitySubpix; -/*--------------------------------------------------------------------------*/ - FxaaFloat pixelOffsetGood = goodSpan ? pixelOffset : 0.0; - FxaaFloat pixelOffsetSubpix = max(pixelOffsetGood, subpixH); - if(!horzSpan) posM.x += pixelOffsetSubpix * lengthSign; - if( horzSpan) posM.y += pixelOffsetSubpix * lengthSign; - #if (FXAA_DISCARD == 1) - return FxaaTexTop(tex, posM); - #else - return FxaaFloat4(FxaaTexTop(tex, posM).xyz, lumaM); - #endif -} -/*==========================================================================*/ -#endif - - - - -/*============================================================================ - - FXAA3 CONSOLE - PC VERSION - ------------------------------------------------------------------------------- -Instead of using this on PC, I'd suggest just using FXAA Quality with - #define FXAA_QUALITY__PRESET 10 -Or - #define FXAA_QUALITY__PRESET 20 -Either are higher qualilty and almost as fast as this on modern PC GPUs. -============================================================================*/ -#if (FXAA_PC_CONSOLE == 1) -/*--------------------------------------------------------------------------*/ -FxaaFloat4 FxaaPixelShader( - // See FXAA Quality FxaaPixelShader() source for docs on Inputs! - FxaaFloat2 pos, - FxaaFloat4 fxaaConsolePosPos, - FxaaTex tex, - FxaaTex fxaaConsole360TexExpBiasNegOne, - FxaaTex fxaaConsole360TexExpBiasNegTwo, - FxaaFloat2 fxaaQualityRcpFrame, - FxaaFloat4 fxaaConsoleRcpFrameOpt, - FxaaFloat4 fxaaConsoleRcpFrameOpt2, - FxaaFloat4 fxaaConsole360RcpFrameOpt2, - FxaaFloat fxaaQualitySubpix, - FxaaFloat fxaaQualityEdgeThreshold, - FxaaFloat fxaaQualityEdgeThresholdMin, - FxaaFloat fxaaConsoleEdgeSharpness, - FxaaFloat fxaaConsoleEdgeThreshold, - FxaaFloat fxaaConsoleEdgeThresholdMin, - FxaaFloat4 fxaaConsole360ConstDir -) { -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaNw = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.xy)); - FxaaFloat lumaSw = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.xw)); - FxaaFloat lumaNe = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.zy)); - FxaaFloat lumaSe = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.zw)); -/*--------------------------------------------------------------------------*/ - FxaaFloat4 rgbyM = FxaaTexTop(tex, pos.xy); - #if (FXAA_GREEN_AS_LUMA == 0) - FxaaFloat lumaM = rgbyM.w; - #else - FxaaFloat lumaM = rgbyM.y; - #endif -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaMaxNwSw = max(lumaNw, lumaSw); - lumaNe += 1.0/384.0; - FxaaFloat lumaMinNwSw = min(lumaNw, lumaSw); -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaMaxNeSe = max(lumaNe, lumaSe); - FxaaFloat lumaMinNeSe = min(lumaNe, lumaSe); -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaMax = max(lumaMaxNeSe, lumaMaxNwSw); - FxaaFloat lumaMin = min(lumaMinNeSe, lumaMinNwSw); -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaMaxScaled = lumaMax * fxaaConsoleEdgeThreshold; -/*--------------------------------------------------------------------------*/ - FxaaFloat lumaMinM = min(lumaMin, lumaM); - FxaaFloat lumaMaxScaledClamped = max(fxaaConsoleEdgeThresholdMin, lumaMaxScaled); - FxaaFloat lumaMaxM = max(lumaMax, lumaM); - FxaaFloat dirSwMinusNe = lumaSw - lumaNe; - FxaaFloat lumaMaxSubMinM = lumaMaxM - lumaMinM; - FxaaFloat dirSeMinusNw = lumaSe - lumaNw; - if(lumaMaxSubMinM < lumaMaxScaledClamped) return rgbyM; -/*--------------------------------------------------------------------------*/ - FxaaFloat2 dir; - dir.x = dirSwMinusNe + dirSeMinusNw; - dir.y = dirSwMinusNe - dirSeMinusNw; -/*--------------------------------------------------------------------------*/ - FxaaFloat2 dir1 = normalize(dir.xy); - FxaaFloat4 rgbyN1 = FxaaTexTop(tex, pos.xy - dir1 * fxaaConsoleRcpFrameOpt.zw); - FxaaFloat4 rgbyP1 = FxaaTexTop(tex, pos.xy + dir1 * fxaaConsoleRcpFrameOpt.zw); -/*--------------------------------------------------------------------------*/ - FxaaFloat dirAbsMinTimesC = min(abs(dir1.x), abs(dir1.y)) * fxaaConsoleEdgeSharpness; - FxaaFloat2 dir2 = clamp(dir1.xy / dirAbsMinTimesC, -2.0, 2.0); -/*--------------------------------------------------------------------------*/ - FxaaFloat4 rgbyN2 = FxaaTexTop(tex, pos.xy - dir2 * fxaaConsoleRcpFrameOpt2.zw); - FxaaFloat4 rgbyP2 = FxaaTexTop(tex, pos.xy + dir2 * fxaaConsoleRcpFrameOpt2.zw); -/*--------------------------------------------------------------------------*/ - FxaaFloat4 rgbyA = rgbyN1 + rgbyP1; - FxaaFloat4 rgbyB = ((rgbyN2 + rgbyP2) * 0.25) + (rgbyA * 0.25); -/*--------------------------------------------------------------------------*/ - #if (FXAA_GREEN_AS_LUMA == 0) - FxaaBool twoTap = (rgbyB.w < lumaMin) || (rgbyB.w > lumaMax); - #else - FxaaBool twoTap = (rgbyB.y < lumaMin) || (rgbyB.y > lumaMax); - #endif - if(twoTap) rgbyB.xyz = rgbyA.xyz * 0.5; - return rgbyB; } -/*==========================================================================*/ -#endif - - - -/*============================================================================ - - FXAA3 CONSOLE - 360 PIXEL SHADER - ------------------------------------------------------------------------------- -This optimized version thanks to suggestions from Andy Luedke. -Should be fully tex bound in all cases. -As of the FXAA 3.11 release, I have still not tested this code, -however I fixed a bug which was in both FXAA 3.9 and FXAA 3.10. -And note this is replacing the old unoptimized version. -If it does not work, please let me know so I can fix it. -============================================================================*/ -#if (FXAA_360 == 1) -/*--------------------------------------------------------------------------*/ -[reduceTempRegUsage(4)] -float4 FxaaPixelShader( - // See FXAA Quality FxaaPixelShader() source for docs on Inputs! - FxaaFloat2 pos, - FxaaFloat4 fxaaConsolePosPos, - FxaaTex tex, - FxaaTex fxaaConsole360TexExpBiasNegOne, - FxaaTex fxaaConsole360TexExpBiasNegTwo, - FxaaFloat2 fxaaQualityRcpFrame, - FxaaFloat4 fxaaConsoleRcpFrameOpt, - FxaaFloat4 fxaaConsoleRcpFrameOpt2, - FxaaFloat4 fxaaConsole360RcpFrameOpt2, - FxaaFloat fxaaQualitySubpix, - FxaaFloat fxaaQualityEdgeThreshold, - FxaaFloat fxaaQualityEdgeThresholdMin, - FxaaFloat fxaaConsoleEdgeSharpness, - FxaaFloat fxaaConsoleEdgeThreshold, - FxaaFloat fxaaConsoleEdgeThresholdMin, - FxaaFloat4 fxaaConsole360ConstDir -) { -/*--------------------------------------------------------------------------*/ - float4 lumaNwNeSwSe; - #if (FXAA_GREEN_AS_LUMA == 0) - asm { - tfetch2D lumaNwNeSwSe.w___, tex, pos.xy, OffsetX = -0.5, OffsetY = -0.5, UseComputedLOD=false - tfetch2D lumaNwNeSwSe._w__, tex, pos.xy, OffsetX = 0.5, OffsetY = -0.5, UseComputedLOD=false - tfetch2D lumaNwNeSwSe.__w_, tex, pos.xy, OffsetX = -0.5, OffsetY = 0.5, UseComputedLOD=false - tfetch2D lumaNwNeSwSe.___w, tex, pos.xy, OffsetX = 0.5, OffsetY = 0.5, UseComputedLOD=false - }; - #else - asm { - tfetch2D lumaNwNeSwSe.y___, tex, pos.xy, OffsetX = -0.5, OffsetY = -0.5, UseComputedLOD=false - tfetch2D lumaNwNeSwSe._y__, tex, pos.xy, OffsetX = 0.5, OffsetY = -0.5, UseComputedLOD=false - tfetch2D lumaNwNeSwSe.__y_, tex, pos.xy, OffsetX = -0.5, OffsetY = 0.5, UseComputedLOD=false - tfetch2D lumaNwNeSwSe.___y, tex, pos.xy, OffsetX = 0.5, OffsetY = 0.5, UseComputedLOD=false - }; - #endif -/*--------------------------------------------------------------------------*/ - lumaNwNeSwSe.y += 1.0/384.0; - float2 lumaMinTemp = min(lumaNwNeSwSe.xy, lumaNwNeSwSe.zw); - float2 lumaMaxTemp = max(lumaNwNeSwSe.xy, lumaNwNeSwSe.zw); - float lumaMin = min(lumaMinTemp.x, lumaMinTemp.y); - float lumaMax = max(lumaMaxTemp.x, lumaMaxTemp.y); -/*--------------------------------------------------------------------------*/ - float4 rgbyM = tex2Dlod(tex, float4(pos.xy, 0.0, 0.0)); - #if (FXAA_GREEN_AS_LUMA == 0) - float lumaMinM = min(lumaMin, rgbyM.w); - float lumaMaxM = max(lumaMax, rgbyM.w); - #else - float lumaMinM = min(lumaMin, rgbyM.y); - float lumaMaxM = max(lumaMax, rgbyM.y); - #endif - if((lumaMaxM - lumaMinM) < max(fxaaConsoleEdgeThresholdMin, lumaMax * fxaaConsoleEdgeThreshold)) return rgbyM; -/*--------------------------------------------------------------------------*/ - float2 dir; - dir.x = dot(lumaNwNeSwSe, fxaaConsole360ConstDir.yyxx); - dir.y = dot(lumaNwNeSwSe, fxaaConsole360ConstDir.xyxy); - dir = normalize(dir); -/*--------------------------------------------------------------------------*/ - float4 dir1 = dir.xyxy * fxaaConsoleRcpFrameOpt.xyzw; -/*--------------------------------------------------------------------------*/ - float4 dir2; - float dirAbsMinTimesC = min(abs(dir.x), abs(dir.y)) * fxaaConsoleEdgeSharpness; - dir2 = saturate(fxaaConsole360ConstDir.zzww * dir.xyxy / dirAbsMinTimesC + 0.5); - dir2 = dir2 * fxaaConsole360RcpFrameOpt2.xyxy + fxaaConsole360RcpFrameOpt2.zwzw; -/*--------------------------------------------------------------------------*/ - float4 rgbyN1 = tex2Dlod(fxaaConsole360TexExpBiasNegOne, float4(pos.xy + dir1.xy, 0.0, 0.0)); - float4 rgbyP1 = tex2Dlod(fxaaConsole360TexExpBiasNegOne, float4(pos.xy + dir1.zw, 0.0, 0.0)); - float4 rgbyN2 = tex2Dlod(fxaaConsole360TexExpBiasNegTwo, float4(pos.xy + dir2.xy, 0.0, 0.0)); - float4 rgbyP2 = tex2Dlod(fxaaConsole360TexExpBiasNegTwo, float4(pos.xy + dir2.zw, 0.0, 0.0)); -/*--------------------------------------------------------------------------*/ - float4 rgbyA = rgbyN1 + rgbyP1; - float4 rgbyB = rgbyN2 + rgbyP2 + rgbyA * 0.5; -/*--------------------------------------------------------------------------*/ - float4 rgbyR = ((FxaaLuma(rgbyB) - lumaMax) > 0.0) ? rgbyA : rgbyB; - rgbyR = ((FxaaLuma(rgbyB) - lumaMin) > 0.0) ? rgbyR : rgbyA; - return rgbyR; } -/*==========================================================================*/ -#endif - - - -/*============================================================================ - - FXAA3 CONSOLE - OPTIMIZED PS3 PIXEL SHADER (NO EARLY EXIT) - -============================================================================== -The code below does not exactly match the assembly. -I have a feeling that 12 cycles is possible, but was not able to get there. -Might have to increase register count to get full performance. -Note this shader does not use perspective interpolation. - -Use the following cgc options, - - --fenable-bx2 --fastmath --fastprecision --nofloatbindings - ------------------------------------------------------------------------------- - NVSHADERPERF OUTPUT ------------------------------------------------------------------------------- -For reference and to aid in debug, output of NVShaderPerf should match this, - -Shader to schedule: - 0: texpkb h0.w(TRUE), v5.zyxx, #0 - 2: addh h2.z(TRUE), h0.w, constant(0.001953, 0.000000, 0.000000, 0.000000).x - 4: texpkb h0.w(TRUE), v5.xwxx, #0 - 6: addh h0.z(TRUE), -h2, h0.w - 7: texpkb h1.w(TRUE), v5, #0 - 9: addh h0.x(TRUE), h0.z, -h1.w - 10: addh h3.w(TRUE), h0.z, h1 - 11: texpkb h2.w(TRUE), v5.zwzz, #0 - 13: addh h0.z(TRUE), h3.w, -h2.w - 14: addh h0.x(TRUE), h2.w, h0 - 15: nrmh h1.xz(TRUE), h0_n - 16: minh_m8 h0.x(TRUE), |h1|, |h1.z| - 17: maxh h4.w(TRUE), h0, h1 - 18: divx h2.xy(TRUE), h1_n.xzzw, h0_n - 19: movr r1.zw(TRUE), v4.xxxy - 20: madr r2.xz(TRUE), -h1, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).zzww, r1.zzww - 22: minh h5.w(TRUE), h0, h1 - 23: texpkb h0(TRUE), r2.xzxx, #0 - 25: madr r0.zw(TRUE), h1.xzxz, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w), r1 - 27: maxh h4.x(TRUE), h2.z, h2.w - 28: texpkb h1(TRUE), r0.zwzz, #0 - 30: addh_d2 h1(TRUE), h0, h1 - 31: madr r0.xy(TRUE), -h2, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).xyxx, r1.zwzz - 33: texpkb h0(TRUE), r0, #0 - 35: minh h4.z(TRUE), h2, h2.w - 36: fenct TRUE - 37: madr r1.xy(TRUE), h2, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).xyxx, r1.zwzz - 39: texpkb h2(TRUE), r1, #0 - 41: addh_d2 h0(TRUE), h0, h2 - 42: maxh h2.w(TRUE), h4, h4.x - 43: minh h2.x(TRUE), h5.w, h4.z - 44: addh_d2 h0(TRUE), h0, h1 - 45: slth h2.x(TRUE), h0.w, h2 - 46: sgth h2.w(TRUE), h0, h2 - 47: movh h0(TRUE), h0 - 48: addx.c0 rc(TRUE), h2, h2.w - 49: movh h0(c0.NE.x), h1 - -IPU0 ------ Simplified schedule: -------- -Pass | Unit | uOp | PC: Op ------+--------+------+------------------------- - 1 | SCT0/1 | mov | 0: TXLr h0.w, g[TEX1].zyxx, const.xxxx, TEX0; - | TEX | txl | 0: TXLr h0.w, g[TEX1].zyxx, const.xxxx, TEX0; - | SCB1 | add | 2: ADDh h2.z, h0.--w-, const.--x-; - | | | - 2 | SCT0/1 | mov | 4: TXLr h0.w, g[TEX1].xwxx, const.xxxx, TEX0; - | TEX | txl | 4: TXLr h0.w, g[TEX1].xwxx, const.xxxx, TEX0; - | SCB1 | add | 6: ADDh h0.z,-h2, h0.--w-; - | | | - 3 | SCT0/1 | mov | 7: TXLr h1.w, g[TEX1], const.xxxx, TEX0; - | TEX | txl | 7: TXLr h1.w, g[TEX1], const.xxxx, TEX0; - | SCB0 | add | 9: ADDh h0.x, h0.z---,-h1.w---; - | SCB1 | add | 10: ADDh h3.w, h0.---z, h1; - | | | - 4 | SCT0/1 | mov | 11: TXLr h2.w, g[TEX1].zwzz, const.xxxx, TEX0; - | TEX | txl | 11: TXLr h2.w, g[TEX1].zwzz, const.xxxx, TEX0; - | SCB0 | add | 14: ADDh h0.x, h2.w---, h0; - | SCB1 | add | 13: ADDh h0.z, h3.--w-,-h2.--w-; - | | | - 5 | SCT1 | mov | 15: NRMh h1.xz, h0; - | SRB | nrm | 15: NRMh h1.xz, h0; - | SCB0 | min | 16: MINh*8 h0.x, |h1|, |h1.z---|; - | SCB1 | max | 17: MAXh h4.w, h0, h1; - | | | - 6 | SCT0 | div | 18: DIVx h2.xy, h1.xz--, h0; - | SCT1 | mov | 19: MOVr r1.zw, g[TEX0].--xy; - | SCB0 | mad | 20: MADr r2.xz,-h1, const.z-w-, r1.z-w-; - | SCB1 | min | 22: MINh h5.w, h0, h1; - | | | - 7 | SCT0/1 | mov | 23: TXLr h0, r2.xzxx, const.xxxx, TEX0; - | TEX | txl | 23: TXLr h0, r2.xzxx, const.xxxx, TEX0; - | SCB0 | max | 27: MAXh h4.x, h2.z---, h2.w---; - | SCB1 | mad | 25: MADr r0.zw, h1.--xz, const, r1; - | | | - 8 | SCT0/1 | mov | 28: TXLr h1, r0.zwzz, const.xxxx, TEX0; - | TEX | txl | 28: TXLr h1, r0.zwzz, const.xxxx, TEX0; - | SCB0/1 | add | 30: ADDh/2 h1, h0, h1; - | | | - 9 | SCT0 | mad | 31: MADr r0.xy,-h2, const.xy--, r1.zw--; - | SCT1 | mov | 33: TXLr h0, r0, const.zzzz, TEX0; - | TEX | txl | 33: TXLr h0, r0, const.zzzz, TEX0; - | SCB1 | min | 35: MINh h4.z, h2, h2.--w-; - | | | - 10 | SCT0 | mad | 37: MADr r1.xy, h2, const.xy--, r1.zw--; - | SCT1 | mov | 39: TXLr h2, r1, const.zzzz, TEX0; - | TEX | txl | 39: TXLr h2, r1, const.zzzz, TEX0; - | SCB0/1 | add | 41: ADDh/2 h0, h0, h2; - | | | - 11 | SCT0 | min | 43: MINh h2.x, h5.w---, h4.z---; - | SCT1 | max | 42: MAXh h2.w, h4, h4.---x; - | SCB0/1 | add | 44: ADDh/2 h0, h0, h1; - | | | - 12 | SCT0 | set | 45: SLTh h2.x, h0.w---, h2; - | SCT1 | set | 46: SGTh h2.w, h0, h2; - | SCB0/1 | mul | 47: MOVh h0, h0; - | | | - 13 | SCT0 | mad | 48: ADDxc0_s rc, h2, h2.w---; - | SCB0/1 | mul | 49: MOVh h0(NE0.xxxx), h1; - -Pass SCT TEX SCB - 1: 0% 100% 25% - 2: 0% 100% 25% - 3: 0% 100% 50% - 4: 0% 100% 50% - 5: 0% 0% 50% - 6: 100% 0% 75% - 7: 0% 100% 75% - 8: 0% 100% 100% - 9: 0% 100% 25% - 10: 0% 100% 100% - 11: 50% 0% 100% - 12: 50% 0% 100% - 13: 25% 0% 100% - -MEAN: 17% 61% 67% - -Pass SCT0 SCT1 TEX SCB0 SCB1 - 1: 0% 0% 100% 0% 100% - 2: 0% 0% 100% 0% 100% - 3: 0% 0% 100% 100% 100% - 4: 0% 0% 100% 100% 100% - 5: 0% 0% 0% 100% 100% - 6: 100% 100% 0% 100% 100% - 7: 0% 0% 100% 100% 100% - 8: 0% 0% 100% 100% 100% - 9: 0% 0% 100% 0% 100% - 10: 0% 0% 100% 100% 100% - 11: 100% 100% 0% 100% 100% - 12: 100% 100% 0% 100% 100% - 13: 100% 0% 0% 100% 100% - -MEAN: 30% 23% 61% 76% 100% -Fragment Performance Setup: Driver RSX Compiler, GPU RSX, Flags 0x5 -Results 13 cycles, 3 r regs, 923,076,923 pixels/s -============================================================================*/ -#if (FXAA_PS3 == 1) && (FXAA_EARLY_EXIT == 0) -/*--------------------------------------------------------------------------*/ -#pragma regcount 7 -#pragma disablepc all -#pragma option O3 -#pragma option OutColorPrec=fp16 -#pragma texformat default RGBA8 -/*==========================================================================*/ -half4 FxaaPixelShader( - // See FXAA Quality FxaaPixelShader() source for docs on Inputs! - FxaaFloat2 pos, - FxaaFloat4 fxaaConsolePosPos, - FxaaTex tex, - FxaaTex fxaaConsole360TexExpBiasNegOne, - FxaaTex fxaaConsole360TexExpBiasNegTwo, - FxaaFloat2 fxaaQualityRcpFrame, - FxaaFloat4 fxaaConsoleRcpFrameOpt, - FxaaFloat4 fxaaConsoleRcpFrameOpt2, - FxaaFloat4 fxaaConsole360RcpFrameOpt2, - FxaaFloat fxaaQualitySubpix, - FxaaFloat fxaaQualityEdgeThreshold, - FxaaFloat fxaaQualityEdgeThresholdMin, - FxaaFloat fxaaConsoleEdgeSharpness, - FxaaFloat fxaaConsoleEdgeThreshold, - FxaaFloat fxaaConsoleEdgeThresholdMin, - FxaaFloat4 fxaaConsole360ConstDir -) { -/*--------------------------------------------------------------------------*/ -// (1) - half4 dir; - half4 lumaNe = h4tex2Dlod(tex, half4(fxaaConsolePosPos.zy, 0, 0)); - #if (FXAA_GREEN_AS_LUMA == 0) - lumaNe.w += half(1.0/512.0); - dir.x = -lumaNe.w; - dir.z = -lumaNe.w; - #else - lumaNe.y += half(1.0/512.0); - dir.x = -lumaNe.y; - dir.z = -lumaNe.y; - #endif -/*--------------------------------------------------------------------------*/ -// (2) - half4 lumaSw = h4tex2Dlod(tex, half4(fxaaConsolePosPos.xw, 0, 0)); - #if (FXAA_GREEN_AS_LUMA == 0) - dir.x += lumaSw.w; - dir.z += lumaSw.w; - #else - dir.x += lumaSw.y; - dir.z += lumaSw.y; - #endif -/*--------------------------------------------------------------------------*/ -// (3) - half4 lumaNw = h4tex2Dlod(tex, half4(fxaaConsolePosPos.xy, 0, 0)); - #if (FXAA_GREEN_AS_LUMA == 0) - dir.x -= lumaNw.w; - dir.z += lumaNw.w; - #else - dir.x -= lumaNw.y; - dir.z += lumaNw.y; - #endif -/*--------------------------------------------------------------------------*/ -// (4) - half4 lumaSe = h4tex2Dlod(tex, half4(fxaaConsolePosPos.zw, 0, 0)); - #if (FXAA_GREEN_AS_LUMA == 0) - dir.x += lumaSe.w; - dir.z -= lumaSe.w; - #else - dir.x += lumaSe.y; - dir.z -= lumaSe.y; - #endif -/*--------------------------------------------------------------------------*/ -// (5) - half4 dir1_pos; - dir1_pos.xy = normalize(dir.xyz).xz; - half dirAbsMinTimesC = min(abs(dir1_pos.x), abs(dir1_pos.y)) * half(FXAA_CONSOLE__PS3_EDGE_SHARPNESS); -/*--------------------------------------------------------------------------*/ -// (6) - half4 dir2_pos; - dir2_pos.xy = clamp(dir1_pos.xy / dirAbsMinTimesC, half(-2.0), half(2.0)); - dir1_pos.zw = pos.xy; - dir2_pos.zw = pos.xy; - half4 temp1N; - temp1N.xy = dir1_pos.zw - dir1_pos.xy * fxaaConsoleRcpFrameOpt.zw; -/*--------------------------------------------------------------------------*/ -// (7) - temp1N = h4tex2Dlod(tex, half4(temp1N.xy, 0.0, 0.0)); - half4 rgby1; - rgby1.xy = dir1_pos.zw + dir1_pos.xy * fxaaConsoleRcpFrameOpt.zw; -/*--------------------------------------------------------------------------*/ -// (8) - rgby1 = h4tex2Dlod(tex, half4(rgby1.xy, 0.0, 0.0)); - rgby1 = (temp1N + rgby1) * 0.5; -/*--------------------------------------------------------------------------*/ -// (9) - half4 temp2N; - temp2N.xy = dir2_pos.zw - dir2_pos.xy * fxaaConsoleRcpFrameOpt2.zw; - temp2N = h4tex2Dlod(tex, half4(temp2N.xy, 0.0, 0.0)); -/*--------------------------------------------------------------------------*/ -// (10) - half4 rgby2; - rgby2.xy = dir2_pos.zw + dir2_pos.xy * fxaaConsoleRcpFrameOpt2.zw; - rgby2 = h4tex2Dlod(tex, half4(rgby2.xy, 0.0, 0.0)); - rgby2 = (temp2N + rgby2) * 0.5; -/*--------------------------------------------------------------------------*/ -// (11) - // compilier moves these scalar ops up to other cycles - #if (FXAA_GREEN_AS_LUMA == 0) - half lumaMin = min(min(lumaNw.w, lumaSw.w), min(lumaNe.w, lumaSe.w)); - half lumaMax = max(max(lumaNw.w, lumaSw.w), max(lumaNe.w, lumaSe.w)); - #else - half lumaMin = min(min(lumaNw.y, lumaSw.y), min(lumaNe.y, lumaSe.y)); - half lumaMax = max(max(lumaNw.y, lumaSw.y), max(lumaNe.y, lumaSe.y)); - #endif - rgby2 = (rgby2 + rgby1) * 0.5; -/*--------------------------------------------------------------------------*/ -// (12) - #if (FXAA_GREEN_AS_LUMA == 0) - bool twoTapLt = rgby2.w < lumaMin; - bool twoTapGt = rgby2.w > lumaMax; - #else - bool twoTapLt = rgby2.y < lumaMin; - bool twoTapGt = rgby2.y > lumaMax; - #endif -/*--------------------------------------------------------------------------*/ -// (13) - if(twoTapLt || twoTapGt) rgby2 = rgby1; -/*--------------------------------------------------------------------------*/ - return rgby2; } -/*==========================================================================*/ -#endif - - - -/*============================================================================ - - FXAA3 CONSOLE - OPTIMIZED PS3 PIXEL SHADER (WITH EARLY EXIT) - -============================================================================== -The code mostly matches the assembly. -I have a feeling that 14 cycles is possible, but was not able to get there. -Might have to increase register count to get full performance. -Note this shader does not use perspective interpolation. - -Use the following cgc options, - - --fenable-bx2 --fastmath --fastprecision --nofloatbindings - -Use of FXAA_GREEN_AS_LUMA currently adds a cycle (16 clks). -Will look at fixing this for FXAA 3.12. ------------------------------------------------------------------------------- - NVSHADERPERF OUTPUT ------------------------------------------------------------------------------- -For reference and to aid in debug, output of NVShaderPerf should match this, - -Shader to schedule: - 0: texpkb h0.w(TRUE), v5.zyxx, #0 - 2: addh h2.y(TRUE), h0.w, constant(0.001953, 0.000000, 0.000000, 0.000000).x - 4: texpkb h1.w(TRUE), v5.xwxx, #0 - 6: addh h0.x(TRUE), h1.w, -h2.y - 7: texpkb h2.w(TRUE), v5.zwzz, #0 - 9: minh h4.w(TRUE), h2.y, h2 - 10: maxh h5.x(TRUE), h2.y, h2.w - 11: texpkb h0.w(TRUE), v5, #0 - 13: addh h3.w(TRUE), -h0, h0.x - 14: addh h0.x(TRUE), h0.w, h0 - 15: addh h0.z(TRUE), -h2.w, h0.x - 16: addh h0.x(TRUE), h2.w, h3.w - 17: minh h5.y(TRUE), h0.w, h1.w - 18: nrmh h2.xz(TRUE), h0_n - 19: minh_m8 h2.w(TRUE), |h2.x|, |h2.z| - 20: divx h4.xy(TRUE), h2_n.xzzw, h2_n.w - 21: movr r1.zw(TRUE), v4.xxxy - 22: maxh h2.w(TRUE), h0, h1 - 23: fenct TRUE - 24: madr r0.xy(TRUE), -h2.xzzw, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).zwzz, r1.zwzz - 26: texpkb h0(TRUE), r0, #0 - 28: maxh h5.x(TRUE), h2.w, h5 - 29: minh h5.w(TRUE), h5.y, h4 - 30: madr r1.xy(TRUE), h2.xzzw, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).zwzz, r1.zwzz - 32: texpkb h2(TRUE), r1, #0 - 34: addh_d2 h2(TRUE), h0, h2 - 35: texpkb h1(TRUE), v4, #0 - 37: maxh h5.y(TRUE), h5.x, h1.w - 38: minh h4.w(TRUE), h1, h5 - 39: madr r0.xy(TRUE), -h4, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).xyxx, r1.zwzz - 41: texpkb h0(TRUE), r0, #0 - 43: addh_m8 h5.z(TRUE), h5.y, -h4.w - 44: madr r2.xy(TRUE), h4, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).xyxx, r1.zwzz - 46: texpkb h3(TRUE), r2, #0 - 48: addh_d2 h0(TRUE), h0, h3 - 49: addh_d2 h3(TRUE), h0, h2 - 50: movh h0(TRUE), h3 - 51: slth h3.x(TRUE), h3.w, h5.w - 52: sgth h3.w(TRUE), h3, h5.x - 53: addx.c0 rc(TRUE), h3.x, h3 - 54: slth.c0 rc(TRUE), h5.z, h5 - 55: movh h0(c0.NE.w), h2 - 56: movh h0(c0.NE.x), h1 - -IPU0 ------ Simplified schedule: -------- -Pass | Unit | uOp | PC: Op ------+--------+------+------------------------- - 1 | SCT0/1 | mov | 0: TXLr h0.w, g[TEX1].zyxx, const.xxxx, TEX0; - | TEX | txl | 0: TXLr h0.w, g[TEX1].zyxx, const.xxxx, TEX0; - | SCB0 | add | 2: ADDh h2.y, h0.-w--, const.-x--; - | | | - 2 | SCT0/1 | mov | 4: TXLr h1.w, g[TEX1].xwxx, const.xxxx, TEX0; - | TEX | txl | 4: TXLr h1.w, g[TEX1].xwxx, const.xxxx, TEX0; - | SCB0 | add | 6: ADDh h0.x, h1.w---,-h2.y---; - | | | - 3 | SCT0/1 | mov | 7: TXLr h2.w, g[TEX1].zwzz, const.xxxx, TEX0; - | TEX | txl | 7: TXLr h2.w, g[TEX1].zwzz, const.xxxx, TEX0; - | SCB0 | max | 10: MAXh h5.x, h2.y---, h2.w---; - | SCB1 | min | 9: MINh h4.w, h2.---y, h2; - | | | - 4 | SCT0/1 | mov | 11: TXLr h0.w, g[TEX1], const.xxxx, TEX0; - | TEX | txl | 11: TXLr h0.w, g[TEX1], const.xxxx, TEX0; - | SCB0 | add | 14: ADDh h0.x, h0.w---, h0; - | SCB1 | add | 13: ADDh h3.w,-h0, h0.---x; - | | | - 5 | SCT0 | mad | 16: ADDh h0.x, h2.w---, h3.w---; - | SCT1 | mad | 15: ADDh h0.z,-h2.--w-, h0.--x-; - | SCB0 | min | 17: MINh h5.y, h0.-w--, h1.-w--; - | | | - 6 | SCT1 | mov | 18: NRMh h2.xz, h0; - | SRB | nrm | 18: NRMh h2.xz, h0; - | SCB1 | min | 19: MINh*8 h2.w, |h2.---x|, |h2.---z|; - | | | - 7 | SCT0 | div | 20: DIVx h4.xy, h2.xz--, h2.ww--; - | SCT1 | mov | 21: MOVr r1.zw, g[TEX0].--xy; - | SCB1 | max | 22: MAXh h2.w, h0, h1; - | | | - 8 | SCT0 | mad | 24: MADr r0.xy,-h2.xz--, const.zw--, r1.zw--; - | SCT1 | mov | 26: TXLr h0, r0, const.xxxx, TEX0; - | TEX | txl | 26: TXLr h0, r0, const.xxxx, TEX0; - | SCB0 | max | 28: MAXh h5.x, h2.w---, h5; - | SCB1 | min | 29: MINh h5.w, h5.---y, h4; - | | | - 9 | SCT0 | mad | 30: MADr r1.xy, h2.xz--, const.zw--, r1.zw--; - | SCT1 | mov | 32: TXLr h2, r1, const.xxxx, TEX0; - | TEX | txl | 32: TXLr h2, r1, const.xxxx, TEX0; - | SCB0/1 | add | 34: ADDh/2 h2, h0, h2; - | | | - 10 | SCT0/1 | mov | 35: TXLr h1, g[TEX0], const.xxxx, TEX0; - | TEX | txl | 35: TXLr h1, g[TEX0], const.xxxx, TEX0; - | SCB0 | max | 37: MAXh h5.y, h5.-x--, h1.-w--; - | SCB1 | min | 38: MINh h4.w, h1, h5; - | | | - 11 | SCT0 | mad | 39: MADr r0.xy,-h4, const.xy--, r1.zw--; - | SCT1 | mov | 41: TXLr h0, r0, const.zzzz, TEX0; - | TEX | txl | 41: TXLr h0, r0, const.zzzz, TEX0; - | SCB0 | mad | 44: MADr r2.xy, h4, const.xy--, r1.zw--; - | SCB1 | add | 43: ADDh*8 h5.z, h5.--y-,-h4.--w-; - | | | - 12 | SCT0/1 | mov | 46: TXLr h3, r2, const.xxxx, TEX0; - | TEX | txl | 46: TXLr h3, r2, const.xxxx, TEX0; - | SCB0/1 | add | 48: ADDh/2 h0, h0, h3; - | | | - 13 | SCT0/1 | mad | 49: ADDh/2 h3, h0, h2; - | SCB0/1 | mul | 50: MOVh h0, h3; - | | | - 14 | SCT0 | set | 51: SLTh h3.x, h3.w---, h5.w---; - | SCT1 | set | 52: SGTh h3.w, h3, h5.---x; - | SCB0 | set | 54: SLThc0 rc, h5.z---, h5; - | SCB1 | add | 53: ADDxc0_s rc, h3.---x, h3; - | | | - 15 | SCT0/1 | mul | 55: MOVh h0(NE0.wwww), h2; - | SCB0/1 | mul | 56: MOVh h0(NE0.xxxx), h1; - -Pass SCT TEX SCB - 1: 0% 100% 25% - 2: 0% 100% 25% - 3: 0% 100% 50% - 4: 0% 100% 50% - 5: 50% 0% 25% - 6: 0% 0% 25% - 7: 100% 0% 25% - 8: 0% 100% 50% - 9: 0% 100% 100% - 10: 0% 100% 50% - 11: 0% 100% 75% - 12: 0% 100% 100% - 13: 100% 0% 100% - 14: 50% 0% 50% - 15: 100% 0% 100% - -MEAN: 26% 60% 56% - -Pass SCT0 SCT1 TEX SCB0 SCB1 - 1: 0% 0% 100% 100% 0% - 2: 0% 0% 100% 100% 0% - 3: 0% 0% 100% 100% 100% - 4: 0% 0% 100% 100% 100% - 5: 100% 100% 0% 100% 0% - 6: 0% 0% 0% 0% 100% - 7: 100% 100% 0% 0% 100% - 8: 0% 0% 100% 100% 100% - 9: 0% 0% 100% 100% 100% - 10: 0% 0% 100% 100% 100% - 11: 0% 0% 100% 100% 100% - 12: 0% 0% 100% 100% 100% - 13: 100% 100% 0% 100% 100% - 14: 100% 100% 0% 100% 100% - 15: 100% 100% 0% 100% 100% - -MEAN: 33% 33% 60% 86% 80% -Fragment Performance Setup: Driver RSX Compiler, GPU RSX, Flags 0x5 -Results 15 cycles, 3 r regs, 800,000,000 pixels/s -============================================================================*/ -#if (FXAA_PS3 == 1) && (FXAA_EARLY_EXIT == 1) -/*--------------------------------------------------------------------------*/ -#pragma regcount 7 -#pragma disablepc all -#pragma option O2 -#pragma option OutColorPrec=fp16 -#pragma texformat default RGBA8 -/*==========================================================================*/ -half4 FxaaPixelShader( - // See FXAA Quality FxaaPixelShader() source for docs on Inputs! - FxaaFloat2 pos, - FxaaFloat4 fxaaConsolePosPos, - FxaaTex tex, - FxaaTex fxaaConsole360TexExpBiasNegOne, - FxaaTex fxaaConsole360TexExpBiasNegTwo, - FxaaFloat2 fxaaQualityRcpFrame, - FxaaFloat4 fxaaConsoleRcpFrameOpt, - FxaaFloat4 fxaaConsoleRcpFrameOpt2, - FxaaFloat4 fxaaConsole360RcpFrameOpt2, - FxaaFloat fxaaQualitySubpix, - FxaaFloat fxaaQualityEdgeThreshold, - FxaaFloat fxaaQualityEdgeThresholdMin, - FxaaFloat fxaaConsoleEdgeSharpness, - FxaaFloat fxaaConsoleEdgeThreshold, - FxaaFloat fxaaConsoleEdgeThresholdMin, - FxaaFloat4 fxaaConsole360ConstDir -) { -/*--------------------------------------------------------------------------*/ -// (1) - half4 rgbyNe = h4tex2Dlod(tex, half4(fxaaConsolePosPos.zy, 0, 0)); - #if (FXAA_GREEN_AS_LUMA == 0) - half lumaNe = rgbyNe.w + half(1.0/512.0); - #else - half lumaNe = rgbyNe.y + half(1.0/512.0); - #endif -/*--------------------------------------------------------------------------*/ -// (2) - half4 lumaSw = h4tex2Dlod(tex, half4(fxaaConsolePosPos.xw, 0, 0)); - #if (FXAA_GREEN_AS_LUMA == 0) - half lumaSwNegNe = lumaSw.w - lumaNe; - #else - half lumaSwNegNe = lumaSw.y - lumaNe; - #endif -/*--------------------------------------------------------------------------*/ -// (3) - half4 lumaNw = h4tex2Dlod(tex, half4(fxaaConsolePosPos.xy, 0, 0)); - #if (FXAA_GREEN_AS_LUMA == 0) - half lumaMaxNwSw = max(lumaNw.w, lumaSw.w); - half lumaMinNwSw = min(lumaNw.w, lumaSw.w); - #else - half lumaMaxNwSw = max(lumaNw.y, lumaSw.y); - half lumaMinNwSw = min(lumaNw.y, lumaSw.y); - #endif -/*--------------------------------------------------------------------------*/ -// (4) - half4 lumaSe = h4tex2Dlod(tex, half4(fxaaConsolePosPos.zw, 0, 0)); - #if (FXAA_GREEN_AS_LUMA == 0) - half dirZ = lumaNw.w + lumaSwNegNe; - half dirX = -lumaNw.w + lumaSwNegNe; - #else - half dirZ = lumaNw.y + lumaSwNegNe; - half dirX = -lumaNw.y + lumaSwNegNe; - #endif -/*--------------------------------------------------------------------------*/ -// (5) - half3 dir; - dir.y = 0.0; - #if (FXAA_GREEN_AS_LUMA == 0) - dir.x = lumaSe.w + dirX; - dir.z = -lumaSe.w + dirZ; - half lumaMinNeSe = min(lumaNe, lumaSe.w); - #else - dir.x = lumaSe.y + dirX; - dir.z = -lumaSe.y + dirZ; - half lumaMinNeSe = min(lumaNe, lumaSe.y); - #endif -/*--------------------------------------------------------------------------*/ -// (6) - half4 dir1_pos; - dir1_pos.xy = normalize(dir).xz; - half dirAbsMinTimes8 = min(abs(dir1_pos.x), abs(dir1_pos.y)) * half(FXAA_CONSOLE__PS3_EDGE_SHARPNESS); -/*--------------------------------------------------------------------------*/ -// (7) - half4 dir2_pos; - dir2_pos.xy = clamp(dir1_pos.xy / dirAbsMinTimes8, half(-2.0), half(2.0)); - dir1_pos.zw = pos.xy; - dir2_pos.zw = pos.xy; - #if (FXAA_GREEN_AS_LUMA == 0) - half lumaMaxNeSe = max(lumaNe, lumaSe.w); - #else - half lumaMaxNeSe = max(lumaNe, lumaSe.y); - #endif -/*--------------------------------------------------------------------------*/ -// (8) - half4 temp1N; - temp1N.xy = dir1_pos.zw - dir1_pos.xy * fxaaConsoleRcpFrameOpt.zw; - temp1N = h4tex2Dlod(tex, half4(temp1N.xy, 0.0, 0.0)); - half lumaMax = max(lumaMaxNwSw, lumaMaxNeSe); - half lumaMin = min(lumaMinNwSw, lumaMinNeSe); -/*--------------------------------------------------------------------------*/ -// (9) - half4 rgby1; - rgby1.xy = dir1_pos.zw + dir1_pos.xy * fxaaConsoleRcpFrameOpt.zw; - rgby1 = h4tex2Dlod(tex, half4(rgby1.xy, 0.0, 0.0)); - rgby1 = (temp1N + rgby1) * 0.5; -/*--------------------------------------------------------------------------*/ -// (10) - half4 rgbyM = h4tex2Dlod(tex, half4(pos.xy, 0.0, 0.0)); - #if (FXAA_GREEN_AS_LUMA == 0) - half lumaMaxM = max(lumaMax, rgbyM.w); - half lumaMinM = min(lumaMin, rgbyM.w); - #else - half lumaMaxM = max(lumaMax, rgbyM.y); - half lumaMinM = min(lumaMin, rgbyM.y); - #endif -/*--------------------------------------------------------------------------*/ -// (11) - half4 temp2N; - temp2N.xy = dir2_pos.zw - dir2_pos.xy * fxaaConsoleRcpFrameOpt2.zw; - temp2N = h4tex2Dlod(tex, half4(temp2N.xy, 0.0, 0.0)); - half4 rgby2; - rgby2.xy = dir2_pos.zw + dir2_pos.xy * fxaaConsoleRcpFrameOpt2.zw; - half lumaRangeM = (lumaMaxM - lumaMinM) / FXAA_CONSOLE__PS3_EDGE_THRESHOLD; -/*--------------------------------------------------------------------------*/ -// (12) - rgby2 = h4tex2Dlod(tex, half4(rgby2.xy, 0.0, 0.0)); - rgby2 = (temp2N + rgby2) * 0.5; -/*--------------------------------------------------------------------------*/ -// (13) - rgby2 = (rgby2 + rgby1) * 0.5; -/*--------------------------------------------------------------------------*/ -// (14) - #if (FXAA_GREEN_AS_LUMA == 0) - bool twoTapLt = rgby2.w < lumaMin; - bool twoTapGt = rgby2.w > lumaMax; - #else - bool twoTapLt = rgby2.y < lumaMin; - bool twoTapGt = rgby2.y > lumaMax; - #endif - bool earlyExit = lumaRangeM < lumaMax; - bool twoTap = twoTapLt || twoTapGt; -/*--------------------------------------------------------------------------*/ -// (15) - if(twoTap) rgby2 = rgby1; - if(earlyExit) rgby2 = rgbyM; -/*--------------------------------------------------------------------------*/ - return rgby2; } -/*==========================================================================*/ -#endif \ No newline at end of file diff --git a/qad/utils/CMakeLists.txt b/utils/CMakeLists.txt similarity index 100% rename from qad/utils/CMakeLists.txt rename to utils/CMakeLists.txt diff --git a/qad/utils/blockeditor/CMakeLists.txt b/utils/blockeditor/CMakeLists.txt similarity index 100% rename from qad/utils/blockeditor/CMakeLists.txt rename to utils/blockeditor/CMakeLists.txt diff --git a/qad/utils/blockeditor/blockeditor_main.cpp b/utils/blockeditor/blockeditor_main.cpp similarity index 100% rename from qad/utils/blockeditor/blockeditor_main.cpp rename to utils/blockeditor/blockeditor_main.cpp diff --git a/qad/utils/blockeditor/icons/blockview.ico b/utils/blockeditor/icons/blockview.ico similarity index 100% rename from qad/utils/blockeditor/icons/blockview.ico rename to utils/blockeditor/icons/blockview.ico diff --git a/qad/utils/blockeditor/icons/blockview.png b/utils/blockeditor/icons/blockview.png similarity index 100% rename from qad/utils/blockeditor/icons/blockview.png rename to utils/blockeditor/icons/blockview.png diff --git a/piqt/utils/cd_pult/CMakeLists.txt b/utils/cd_pult/CMakeLists.txt similarity index 100% rename from piqt/utils/cd_pult/CMakeLists.txt rename to utils/cd_pult/CMakeLists.txt diff --git a/piqt/utils/cd_pult/cddirectk.cpp b/utils/cd_pult/cddirectk.cpp similarity index 100% rename from piqt/utils/cd_pult/cddirectk.cpp rename to utils/cd_pult/cddirectk.cpp diff --git a/piqt/utils/cd_pult/cddirectk.h b/utils/cd_pult/cddirectk.h similarity index 100% rename from piqt/utils/cd_pult/cddirectk.h rename to utils/cd_pult/cddirectk.h diff --git a/piqt/utils/cd_pult/cddirectk.ui b/utils/cd_pult/cddirectk.ui similarity index 100% rename from piqt/utils/cd_pult/cddirectk.ui rename to utils/cd_pult/cddirectk.ui diff --git a/piqt/utils/cd_pult/cddirectk_type_dialog.cpp b/utils/cd_pult/cddirectk_type_dialog.cpp similarity index 100% rename from piqt/utils/cd_pult/cddirectk_type_dialog.cpp rename to utils/cd_pult/cddirectk_type_dialog.cpp diff --git a/piqt/utils/cd_pult/cddirectk_type_dialog.h b/utils/cd_pult/cddirectk_type_dialog.h similarity index 100% rename from piqt/utils/cd_pult/cddirectk_type_dialog.h rename to utils/cd_pult/cddirectk_type_dialog.h diff --git a/piqt/utils/cd_pult/cddirectk_type_dialog.ui b/utils/cd_pult/cddirectk_type_dialog.ui similarity index 100% rename from piqt/utils/cd_pult/cddirectk_type_dialog.ui rename to utils/cd_pult/cddirectk_type_dialog.ui diff --git a/piqt/utils/cd_pult/cdgraphics.cpp b/utils/cd_pult/cdgraphics.cpp similarity index 100% rename from piqt/utils/cd_pult/cdgraphics.cpp rename to utils/cd_pult/cdgraphics.cpp diff --git a/piqt/utils/cd_pult/cdgraphics.h b/utils/cd_pult/cdgraphics.h similarity index 100% rename from piqt/utils/cd_pult/cdgraphics.h rename to utils/cd_pult/cdgraphics.h diff --git a/piqt/utils/cd_pult/cdgraphics.ui b/utils/cd_pult/cdgraphics.ui similarity index 100% rename from piqt/utils/cd_pult/cdgraphics.ui rename to utils/cd_pult/cdgraphics.ui diff --git a/piqt/utils/cd_pult/cdpult.qrc b/utils/cd_pult/cdpult.qrc similarity index 100% rename from piqt/utils/cd_pult/cdpult.qrc rename to utils/cd_pult/cdpult.qrc diff --git a/piqt/utils/cd_pult/cdpultwindow.cpp b/utils/cd_pult/cdpultwindow.cpp similarity index 100% rename from piqt/utils/cd_pult/cdpultwindow.cpp rename to utils/cd_pult/cdpultwindow.cpp diff --git a/piqt/utils/cd_pult/cdpultwindow.h b/utils/cd_pult/cdpultwindow.h similarity index 100% rename from piqt/utils/cd_pult/cdpultwindow.h rename to utils/cd_pult/cdpultwindow.h diff --git a/piqt/utils/cd_pult/cdpultwindow.ui b/utils/cd_pult/cdpultwindow.ui similarity index 100% rename from piqt/utils/cd_pult/cdpultwindow.ui rename to utils/cd_pult/cdpultwindow.ui diff --git a/piqt/utils/cd_pult/cdviewwidget.cpp b/utils/cd_pult/cdviewwidget.cpp similarity index 100% rename from piqt/utils/cd_pult/cdviewwidget.cpp rename to utils/cd_pult/cdviewwidget.cpp diff --git a/piqt/utils/cd_pult/cdviewwidget.h b/utils/cd_pult/cdviewwidget.h similarity index 100% rename from piqt/utils/cd_pult/cdviewwidget.h rename to utils/cd_pult/cdviewwidget.h diff --git a/piqt/utils/cd_pult/cdviewwidget.ui b/utils/cd_pult/cdviewwidget.ui similarity index 100% rename from piqt/utils/cd_pult/cdviewwidget.ui rename to utils/cd_pult/cdviewwidget.ui diff --git a/piqt/utils/cd_pult/icons/Apps-accessories-calculator-icon.png b/utils/cd_pult/icons/Apps-accessories-calculator-icon.png similarity index 100% rename from piqt/utils/cd_pult/icons/Apps-accessories-calculator-icon.png rename to utils/cd_pult/icons/Apps-accessories-calculator-icon.png diff --git a/piqt/utils/cd_pult/icons/accessories-text-editor.png b/utils/cd_pult/icons/accessories-text-editor.png similarity index 100% rename from piqt/utils/cd_pult/icons/accessories-text-editor.png rename to utils/cd_pult/icons/accessories-text-editor.png diff --git a/piqt/utils/cd_pult/icons/db-export.png b/utils/cd_pult/icons/db-export.png similarity index 100% rename from piqt/utils/cd_pult/icons/db-export.png rename to utils/cd_pult/icons/db-export.png diff --git a/piqt/utils/cd_pult/icons/db-import.png b/utils/cd_pult/icons/db-import.png similarity index 100% rename from piqt/utils/cd_pult/icons/db-import.png rename to utils/cd_pult/icons/db-import.png diff --git a/piqt/utils/cd_pult/icons/flame.png b/utils/cd_pult/icons/flame.png similarity index 100% rename from piqt/utils/cd_pult/icons/flame.png rename to utils/cd_pult/icons/flame.png diff --git a/piqt/utils/cd_pult/icons/timer.png b/utils/cd_pult/icons/timer.png similarity index 100% rename from piqt/utils/cd_pult/icons/timer.png rename to utils/cd_pult/icons/timer.png diff --git a/piqt/utils/cd_pult/main.cpp b/utils/cd_pult/main.cpp similarity index 100% rename from piqt/utils/cd_pult/main.cpp rename to utils/cd_pult/main.cpp diff --git a/piqt/utils/piconnedit/CMakeLists.txt b/utils/piconnedit/CMakeLists.txt similarity index 100% rename from piqt/utils/piconnedit/CMakeLists.txt rename to utils/piconnedit/CMakeLists.txt diff --git a/piqt/utils/piconnedit/piconnedit.qrc b/utils/piconnedit/piconnedit.qrc similarity index 100% rename from piqt/utils/piconnedit/piconnedit.qrc rename to utils/piconnedit/piconnedit.qrc diff --git a/piqt/utils/piconnedit/piconnedit_main.cpp b/utils/piconnedit/piconnedit_main.cpp similarity index 100% rename from piqt/utils/piconnedit/piconnedit_main.cpp rename to utils/piconnedit/piconnedit_main.cpp diff --git a/piqt/utils/pidumper/CMakeLists.txt b/utils/pidumper/CMakeLists.txt similarity index 100% rename from piqt/utils/pidumper/CMakeLists.txt rename to utils/pidumper/CMakeLists.txt diff --git a/piqt/utils/pidumper/pidumper.cpp b/utils/pidumper/pidumper.cpp similarity index 100% rename from piqt/utils/pidumper/pidumper.cpp rename to utils/pidumper/pidumper.cpp diff --git a/piqt/utils/pidumper/pidumper.h b/utils/pidumper/pidumper.h similarity index 100% rename from piqt/utils/pidumper/pidumper.h rename to utils/pidumper/pidumper.h diff --git a/piqt/utils/pidumper/pidumper.ui b/utils/pidumper/pidumper.ui similarity index 100% rename from piqt/utils/pidumper/pidumper.ui rename to utils/pidumper/pidumper.ui diff --git a/piqt/utils/pidumper/pidumper_main.cpp b/utils/pidumper/pidumper_main.cpp similarity index 100% rename from piqt/utils/pidumper/pidumper_main.cpp rename to utils/pidumper/pidumper_main.cpp diff --git a/piqt/utils/piintrospector/CMakeLists.txt b/utils/piintrospector/CMakeLists.txt similarity index 100% rename from piqt/utils/piintrospector/CMakeLists.txt rename to utils/piintrospector/CMakeLists.txt diff --git a/piqt/utils/piintrospector/containers_view.cpp b/utils/piintrospector/containers_view.cpp similarity index 100% rename from piqt/utils/piintrospector/containers_view.cpp rename to utils/piintrospector/containers_view.cpp diff --git a/piqt/utils/piintrospector/containers_view.h b/utils/piintrospector/containers_view.h similarity index 100% rename from piqt/utils/piintrospector/containers_view.h rename to utils/piintrospector/containers_view.h diff --git a/piqt/utils/piintrospector/containers_view.ui b/utils/piintrospector/containers_view.ui similarity index 100% rename from piqt/utils/piintrospector/containers_view.ui rename to utils/piintrospector/containers_view.ui diff --git a/piqt/utils/piintrospector/objects_view.cpp b/utils/piintrospector/objects_view.cpp similarity index 100% rename from piqt/utils/piintrospector/objects_view.cpp rename to utils/piintrospector/objects_view.cpp diff --git a/piqt/utils/piintrospector/objects_view.h b/utils/piintrospector/objects_view.h similarity index 100% rename from piqt/utils/piintrospector/objects_view.h rename to utils/piintrospector/objects_view.h diff --git a/piqt/utils/piintrospector/objects_view.ui b/utils/piintrospector/objects_view.ui similarity index 100% rename from piqt/utils/piintrospector/objects_view.ui rename to utils/piintrospector/objects_view.ui diff --git a/piqt/utils/piintrospector/piintrospector.cpp b/utils/piintrospector/piintrospector.cpp similarity index 100% rename from piqt/utils/piintrospector/piintrospector.cpp rename to utils/piintrospector/piintrospector.cpp diff --git a/piqt/utils/piintrospector/piintrospector.h b/utils/piintrospector/piintrospector.h similarity index 100% rename from piqt/utils/piintrospector/piintrospector.h rename to utils/piintrospector/piintrospector.h diff --git a/piqt/utils/piintrospector/piintrospector.ui b/utils/piintrospector/piintrospector.ui similarity index 100% rename from piqt/utils/piintrospector/piintrospector.ui rename to utils/piintrospector/piintrospector.ui diff --git a/piqt/utils/piintrospector/piintrospector_main.cpp b/utils/piintrospector/piintrospector_main.cpp similarity index 100% rename from piqt/utils/piintrospector/piintrospector_main.cpp rename to utils/piintrospector/piintrospector_main.cpp diff --git a/piqt/utils/piintrospector/threads_view.cpp b/utils/piintrospector/threads_view.cpp similarity index 100% rename from piqt/utils/piintrospector/threads_view.cpp rename to utils/piintrospector/threads_view.cpp diff --git a/piqt/utils/piintrospector/threads_view.h b/utils/piintrospector/threads_view.h similarity index 100% rename from piqt/utils/piintrospector/threads_view.h rename to utils/piintrospector/threads_view.h diff --git a/piqt/utils/piintrospector/threads_view.ui b/utils/piintrospector/threads_view.ui similarity index 100% rename from piqt/utils/piintrospector/threads_view.ui rename to utils/piintrospector/threads_view.ui diff --git a/qad/utils/qpicalculator/CMakeLists.txt b/utils/qpicalculator/CMakeLists.txt similarity index 100% rename from qad/utils/qpicalculator/CMakeLists.txt rename to utils/qpicalculator/CMakeLists.txt diff --git a/qad/utils/qpicalculator/icons/qpicalculator.ico b/utils/qpicalculator/icons/qpicalculator.ico similarity index 100% rename from qad/utils/qpicalculator/icons/qpicalculator.ico rename to utils/qpicalculator/icons/qpicalculator.ico diff --git a/qad/utils/qpicalculator/icons/qpicalculator.png b/utils/qpicalculator/icons/qpicalculator.png similarity index 100% rename from qad/utils/qpicalculator/icons/qpicalculator.png rename to utils/qpicalculator/icons/qpicalculator.png diff --git a/qad/utils/qpicalculator/main.cpp b/utils/qpicalculator/main.cpp similarity index 100% rename from qad/utils/qpicalculator/main.cpp rename to utils/qpicalculator/main.cpp diff --git a/qad/utils/qpicalculator/mainwindow.cpp b/utils/qpicalculator/mainwindow.cpp similarity index 100% rename from qad/utils/qpicalculator/mainwindow.cpp rename to utils/qpicalculator/mainwindow.cpp diff --git a/qad/utils/qpicalculator/mainwindow.h b/utils/qpicalculator/mainwindow.h similarity index 100% rename from qad/utils/qpicalculator/mainwindow.h rename to utils/qpicalculator/mainwindow.h diff --git a/qad/utils/qpicalculator/mainwindow.ui b/utils/qpicalculator/mainwindow.ui similarity index 100% rename from qad/utils/qpicalculator/mainwindow.ui rename to utils/qpicalculator/mainwindow.ui diff --git a/qad/utils/qpicalculator/qpicalculator.qrc b/utils/qpicalculator/qpicalculator.qrc similarity index 100% rename from qad/utils/qpicalculator/qpicalculator.qrc rename to utils/qpicalculator/qpicalculator.qrc