diff --git a/Fwk/VizFwk/CMakeLists.txt b/Fwk/VizFwk/CMakeLists.txt index 40c6ca914c..3774693b6a 100644 --- a/Fwk/VizFwk/CMakeLists.txt +++ b/Fwk/VizFwk/CMakeLists.txt @@ -3,6 +3,13 @@ cmake_minimum_required(VERSION 3.15) project(VizFramework) +if (CEE_CEEVIZ_ROOT) + message(STATUS "CEE_CEEVIZ_ROOT: ${CEE_CEEVIZ_ROOT}") +else() + set(CEE_CEEVIZ_ROOT ${PROJECT_SOURCE_DIR}) + message(STATUS "Setting CEE_CEEVIZ_ROOT to ${CEE_CEEVIZ_ROOT}") +endif() + # Determine if we're being run stand-alone or invoked from some other project set(CEE_STAND_ALONE ON) if (PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) @@ -44,7 +51,6 @@ add_subdirectory(ThirdParty/FreeType) add_subdirectory(LibUtilities) - option(CEE_BUILD_GUI_QT "Build GUI library for Qt" ON) if (CEE_BUILD_GUI_QT) option(CEE_USE_QT5 "Use Qt5" ON) @@ -53,27 +59,30 @@ endif() if (CEE_STAND_ALONE) - option(CEE_BUILD_UNIT_TESTS "Build unit tests" ON) - if (CEE_BUILD_UNIT_TESTS) - add_subdirectory(Tests) - endif() + option(CEE_BUILD_TEST_APPS "Build test apps" ON) +endif() +if (CEE_BUILD_UNIT_TESTS OR CEE_BUILD_TEST_APPS) + # Add CeeViz's root source dir as a preprocessor directive so unit tests and test apps can determine where to find the resources they want. + add_definitions(-DCVF_CEEVIZ_ROOT_SOURCE_DIR="${CEE_CEEVIZ_ROOT}") +endif() - option(CEE_BUILD_TEST_APPS "Build test apps" ON) - if (CEE_BUILD_TEST_APPS) - # For now, build the snippet libs here - add_subdirectory(Tests/SnippetsBasis) - - if (CEE_BUILD_GUI_QT) - add_subdirectory(TestApps/Qt/QtMinimal_deprecated) - add_subdirectory(TestApps/Qt/QtMultiView_deprecated) - add_subdirectory(TestApps/Qt/QtSnippetRunner) - endif() - - if (WIN32) - add_subdirectory(TestApps/Win32/Win32SnippetRunner) - endif() +if (CEE_BUILD_UNIT_TESTS) + add_subdirectory(Tests) +endif() + +if (CEE_BUILD_TEST_APPS) + # For now, build the snippet libs here + add_subdirectory(Tests/SnippetsBasis) + + if (CEE_BUILD_GUI_QT) + add_subdirectory(TestApps/Qt/QtMinimal_deprecated) + add_subdirectory(TestApps/Qt/QtMultiView_deprecated) + add_subdirectory(TestApps/Qt/QtSnippetRunner) endif() + if (WIN32) + add_subdirectory(TestApps/Win32/Win32SnippetRunner) + endif() endif() diff --git a/Fwk/VizFwk/LibRender/cvfShader.cpp b/Fwk/VizFwk/LibRender/cvfShader.cpp index cc037a47fd..f578ff6f9e 100644 --- a/Fwk/VizFwk/LibRender/cvfShader.cpp +++ b/Fwk/VizFwk/LibRender/cvfShader.cpp @@ -181,6 +181,16 @@ bool Shader::compile(OpenGLContext* oglContext) String errStr = String("Error compiling shader: '%1'\n").arg(m_shaderName); errStr += "GLSL details:\n"; errStr += shaderInfoLog(oglContext); + + // { + // errStr += "Shader prog:\n"; + // std::vector progArr = m_source.split("\n"); + // for (size_t i = 0; i < progArr.size(); ++i) + // { + // errStr += String("%1: %2\n").arg(static_cast(i + 1), 3).arg(progArr[i]); + // } + // } + CVF_LOG_RENDER_ERROR(oglContext, errStr); return false; } diff --git a/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/CMakeLists.txt b/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/CMakeLists.txt index 9f46f71802..bf7e29aef4 100644 --- a/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/CMakeLists.txt +++ b/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/CMakeLists.txt @@ -35,6 +35,15 @@ QSRStdInclude.cpp QSRTranslateEvent.cpp ) +set(CEE_HEADER_FILES +QSRCommandLineArgs.h +QSRPropertiesPanel.h +QSRRunPanel.h +QSRSnippetWidget.h +QSRStdInclude.h +QSRTranslateEvent.h +) + # Headers that need MOCing set(MOC_HEADER_FILES QSRMainWindow.h @@ -57,5 +66,5 @@ if (CMAKE_COMPILER_IS_GNUCXX) set(SYSTEM_LIBRARIES -lrt -lpthread) endif(CMAKE_COMPILER_IS_GNUCXX) -add_executable(${PROJECT_NAME} ${CEE_SOURCE_FILES} ${MOC_SOURCE_FILES}) +add_executable(${PROJECT_NAME} ${CEE_SOURCE_FILES} ${CEE_HEADER_FILES} ${MOC_SOURCE_FILES}) target_link_libraries(${PROJECT_NAME} ${CEE_LIBS} ${OPENGL_LIBRARIES} ${QT_LIBRARIES} ${SYSTEM_LIBRARIES}) diff --git a/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/QSRMain.cpp b/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/QSRMain.cpp index b619acdb37..1bf2662f97 100644 --- a/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/QSRMain.cpp +++ b/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/QSRMain.cpp @@ -60,9 +60,12 @@ int main(int argc, char *argv[]) // On Linux, Qt will use the system locale, force number formatting settings back to "C" locale setlocale(LC_NUMERIC,"C"); - // These directories are correct when running from within visual studio - cvf::String testDataDir = "../../../Tests/TestData/"; - cvf::String shaderDir = "../../../Tests/SnippetsBasis/Shaders/"; + cvf::String testDataDir = ""; + cvf::String shaderDir = ""; +#ifdef CVF_CEEVIZ_ROOT_SOURCE_DIR + testDataDir = CVF_CEEVIZ_ROOT_SOURCE_DIR "/Tests/TestData/"; + shaderDir = CVF_CEEVIZ_ROOT_SOURCE_DIR "/Tests/SnippetsBasis/Shaders/"; +#endif { QSRCommandLineArgs cmdLineArgs; diff --git a/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/TriggerTBBCopy.txt b/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/TriggerTBBCopy.txt deleted file mode 100644 index bf816d39e4..0000000000 --- a/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/TriggerTBBCopy.txt +++ /dev/null @@ -1,2 +0,0 @@ - -Sole purpose of this file is to have custom build rules to trigger copying of TBB DLLs diff --git a/Fwk/VizFwk/TestApps/Win32/Win32SnippetRunner/Win32SnippetRunner.cpp b/Fwk/VizFwk/TestApps/Win32/Win32SnippetRunner/Win32SnippetRunner.cpp index 47bb4fc16f..376e5e9424 100644 --- a/Fwk/VizFwk/TestApps/Win32/Win32SnippetRunner/Win32SnippetRunner.cpp +++ b/Fwk/VizFwk/TestApps/Win32/Win32SnippetRunner/Win32SnippetRunner.cpp @@ -69,11 +69,11 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCm UNREFERENCED_PARAMETER(lpCmdLine); cvf::ShaderSourceProvider* shaderProvider = cvf::ShaderSourceProvider::instance(); - shaderProvider->setSourceRepository(new cvf::ShaderSourceRepositoryFile("../../../LibRender/glsl/")); - shaderProvider->addFileSearchDirectory("../../../Tests/SnippetsBasis/Shaders/"); + shaderProvider->setSourceRepository(new cvf::ShaderSourceRepositoryFile(CVF_CEEVIZ_ROOT_SOURCE_DIR "/LibRender/glsl/")); + shaderProvider->addFileSearchDirectory(CVF_CEEVIZ_ROOT_SOURCE_DIR "/Tests/SnippetsBasis/Shaders/"); shaderProvider->addFileSearchDirectory("./"); - const cvf::String testDataDir = "../../../Tests/TestData/"; + const cvf::String testDataDir = CVF_CEEVIZ_ROOT_SOURCE_DIR "/Tests/TestData/"; cvfu::SnippetFactory* factoryBasis = new SnippetFactoryBasis; factoryBasis->setTestDataDir(testDataDir); @@ -168,7 +168,8 @@ LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar { //ref snippet = SnippetRegistry::instance()->createSnippet("snip::MinimalModel"); //ref snippet = SnippetRegistry::instance()->createSnippet("snip::Highlight"); - ref snippet = SnippetRegistry::instance()->createSnippet("snip::Stencil"); + //ref snippet = SnippetRegistry::instance()->createSnippet("snip::Stencil"); + ref snippet = SnippetRegistry::instance()->createSnippet("snip::TransparentWeightedAverage"); sl_snippetWnd = new Win32SnippetWindow; sl_snippetWnd->create(hWnd, snippet.p()); SetFocus(sl_snippetWnd->windowHandle()); diff --git a/Fwk/VizFwk/Tests/LibUtilities_UnitTests/LibUtilities_UnitTests.cpp b/Fwk/VizFwk/Tests/LibUtilities_UnitTests/LibUtilities_UnitTests.cpp index 29d5b81245..1821092558 100644 --- a/Fwk/VizFwk/Tests/LibUtilities_UnitTests/LibUtilities_UnitTests.cpp +++ b/Fwk/VizFwk/Tests/LibUtilities_UnitTests/LibUtilities_UnitTests.cpp @@ -38,7 +38,7 @@ #include "cvfBase.h" #include "gtest/gtest.h" -#include "gtest/cvftestUtils.h" + #include @@ -54,7 +54,5 @@ int main(int argc, char **argv) testing::InitGoogleTest(&argc, argv); - cvftest::TestDataDir::initializeInstance(cvftest::TestDataDir::DEFAULT_DEFINE_THEN_VIZ_FRAMEWORK, true); - return RUN_ALL_TESTS(); } diff --git a/Fwk/VizFwk/Tests/LibUtilities_UnitTests/cvfuImageTga-Test.cpp b/Fwk/VizFwk/Tests/LibUtilities_UnitTests/cvfuImageTga-Test.cpp index cf09c6326e..e4a4927142 100644 --- a/Fwk/VizFwk/Tests/LibUtilities_UnitTests/cvfuImageTga-Test.cpp +++ b/Fwk/VizFwk/Tests/LibUtilities_UnitTests/cvfuImageTga-Test.cpp @@ -51,7 +51,7 @@ using namespace cvfu; //-------------------------------------------------------------------------------------------------- TEST(ImageTgaTest, LoadUncompressed24bit) { - String fullFileName = cvftest::TestDataDir::instance()->dataDir() + "TgaTestSuite/UTC24.TGA"; + String fullFileName = cvftest::Utils::getTestDataDir() + "TgaTestSuite/UTC24.TGA"; cvf::Trace::show("FN: %s\n", fullFileName.toAscii().ptr()); ref img = ImageTga::loadImage(fullFileName); ASSERT_TRUE(img.notNull()); @@ -68,7 +68,7 @@ TEST(ImageTgaTest, LoadUncompressed24bit) //-------------------------------------------------------------------------------------------------- TEST(ImageTgaTest, LoadCompressed24bit) { - String fullFileName = cvftest::TestDataDir::instance()->dataDir() + "TgaTestSuite/CTC24.TGA"; + String fullFileName = cvftest::Utils::getTestDataDir() + "TgaTestSuite/CTC24.TGA"; cvf::Trace::show("FN: %s\n", fullFileName.toAscii().ptr()); ref img = ImageTga::loadImage(fullFileName); ASSERT_TRUE(img.notNull()); @@ -85,7 +85,7 @@ TEST(ImageTgaTest, LoadCompressed24bit) //-------------------------------------------------------------------------------------------------- TEST(ImageTgaTest, LoadUncompressed32bit) { - String fullFileName = cvftest::TestDataDir::instance()->dataDir() + "TgaTestSuite/UTC32.TGA"; + String fullFileName = cvftest::Utils::getTestDataDir() + "TgaTestSuite/UTC32.TGA"; ref img = ImageTga::loadImage(fullFileName); ASSERT_TRUE(img.notNull()); @@ -101,7 +101,7 @@ TEST(ImageTgaTest, LoadUncompressed32bit) //-------------------------------------------------------------------------------------------------- TEST(ImageTgaTest, LoadCompressed32bit) { - String fullFileName = cvftest::TestDataDir::instance()->dataDir() + "TgaTestSuite/CTC32.TGA"; + String fullFileName = cvftest::Utils::getTestDataDir() + "TgaTestSuite/CTC32.TGA"; ref img = ImageTga::loadImage(fullFileName); ASSERT_TRUE(img.notNull()); diff --git a/Fwk/VizFwk/Tests/SnippetsBasis/snipTextDrawing.cpp b/Fwk/VizFwk/Tests/SnippetsBasis/snipTextDrawing.cpp index baf53d4830..7e92b530da 100644 --- a/Fwk/VizFwk/Tests/SnippetsBasis/snipTextDrawing.cpp +++ b/Fwk/VizFwk/Tests/SnippetsBasis/snipTextDrawing.cpp @@ -252,13 +252,13 @@ ref TextDrawing::createTextPart() m_textDrawable->setFont(NULL); m_textDrawable->setTextColor(Color3::RED); -// m_textDrawable->addText(L"Text:", cvf::Vec3f(50, 200, 0)); -// m_textDrawable->addText(L" ABCDEFGHIJKLMNOPQRSTUVWXYZÆØÅ", cvf::Vec3f(50, 170, 0)); -// m_textDrawable->addText(L" abcdefghijklmnopqrstuvwxyzæøå", cvf::Vec3f(50, 140, 0)); -// m_textDrawable->addText(L" 0123456789 0123456789 0123456789", cvf::Vec3f(50, 110, 0)); -// m_textDrawable->addText(L" !\"#¤%&/()=?`^*@£$€{[]}´~¨',;.:+-_<>>addText(L" Unicode1: \x03B1\x03B2\x03B3\x03B4\x03B5", cvf::Vec3f(50, 50, 0)); -// m_textDrawable->addText(L" Unicode2: 不仅是因为这两种语言截然不同", cvf::Vec3f(50, 20, 0)); + m_textDrawable->addText(L"Text:", cvf::Vec3f(50, 200, 0)); + m_textDrawable->addText(L" ABCDEFGHIJKLMNOPQRSTUVWXYZÆØÅ", cvf::Vec3f(50, 170, 0)); + m_textDrawable->addText(L" abcdefghijklmnopqrstuvwxyzæøå", cvf::Vec3f(50, 140, 0)); + m_textDrawable->addText(L" 0123456789 0123456789 0123456789", cvf::Vec3f(50, 110, 0)); + m_textDrawable->addText(L" !\"#¤%&/()=?`^*@£$€{[]}´~¨',;.:+-_<>>addText(L" Unicode1: \x03B1\x03B2\x03B3\x03B4\x03B5", cvf::Vec3f(50, 50, 0)); + m_textDrawable->addText(L" Unicode2: 不仅是因为这两种语言截然不同", cvf::Vec3f(50, 20, 0)); // Set up transparency ref blending = new RenderStateBlending; diff --git a/Fwk/VizFwk/ThirdParty/gtest/cvftestUtils.h b/Fwk/VizFwk/ThirdParty/gtest/cvftestUtils.h index cead690dc6..6c01d543ea 100644 --- a/Fwk/VizFwk/ThirdParty/gtest/cvftestUtils.h +++ b/Fwk/VizFwk/ThirdParty/gtest/cvftestUtils.h @@ -2,7 +2,6 @@ namespace cvftest { - //================================================================================================== // // Static helper class for unit tests @@ -11,12 +10,23 @@ namespace cvftest { class Utils { public: - static bool doesEnvironmentVarExist(const char* name) - { - const char* env = testing::internal::posix::GetEnv(name); - return env ? true : false; + static cvf::String getTestDataDir() + { + std::string testPath = ""; +#if defined(CVF_CEEVIZ_ROOT_SOURCE_DIR) + testPath = CVF_CEEVIZ_ROOT_SOURCE_DIR "/Tests/TestData/"; +#endif + + std::string testPathEnv = getEnvironmentVar("CVF_UTEST_DATA_DIR"); + if (testPathEnv.length() > 0) + { + testPath = testPathEnv; + } + + return testPath; } +private: static std::string getEnvironmentVar(const char* name) { const char* env = testing::internal::posix::GetEnv(name); @@ -43,149 +53,5 @@ class Utils }; - -//================================================================================================== -// -// Helper for making a test data directory available inside unit tests -// -// The data directories can be specified via the environment variables CVF_UTEST_DATA_DIR and -// CVF_UTEST_EXTRA_DATA_DIR. Expects a the path to contain a trailing slash. -// Linux: export CVF_UTEST_DATA_DIR="../../../Tests/TestData/" -// -// The main data dir may be populated with default values if the environment variable isn't set. -// The DefaultDataDir enum determines which default will be used. -//================================================================================================== -class TestDataDir -{ -public: - // What value to use if the test data dir environment variable isn't set? - enum DefaultDataDir - { - EMPTY_STRING, // Empty string - DEFAULT_DEFINE, // Try and set from the CVF_UTEST_DEFAULT_DATA_DIR define (must of course be defined, typical usage is via CMake) - DEFAULT_DEFINE_THEN_VIZ_FRAMEWORK // First try the define above, then fall back to the default test data directory for VizFramework - }; - -public: - /// Static initialize function that sets up the singleton and initializes - /// the values of the data directories based on value of the specified enum - //-------------------------------------------------------------------------------------------------- - static void initializeInstance(DefaultDataDir defaultDataDir, bool verbose) - { - TestDataDir* theInstance = internalInstance(); - theInstance->initialize(defaultDataDir, verbose); - } - - /// Get pointer to singleton intance, must call initializeInstance() before use - //-------------------------------------------------------------------------------------------------- - static const TestDataDir* instance() - { - const TestDataDir* theInstance = internalInstance(); - if (!theInstance->m_isInitialized) - { - // Not sure if it is wise to use the gtest internal macros here, but haven't found another solution yet - GTEST_MESSAGE_("TestDataDir::initializeInstance() must be called first!", ::testing::TestPartResult::kFatalFailure); - } - return theInstance; - } - - /// Returns the main data directory - //-------------------------------------------------------------------------------------------------- - std::string dataDir() const - { - return m_dataDir; - } - - /// Returns the extra data directory - //-------------------------------------------------------------------------------------------------- - std::string extraDataDir() const - { - return m_extraDataDir; - } - -private: - TestDataDir() - : m_isInitialized(false) - { - } - - // Initializes the data members - void initialize(DefaultDataDir defaultDataDir, bool verbose) - { - std::string valSrcStr = "empty"; - - if (Utils::doesEnvironmentVarExist("CVF_UTEST_DATA_DIR")) - { - m_dataDir = Utils::getEnvironmentVar("CVF_UTEST_DATA_DIR"); - valSrcStr = "environmentVar"; - } - else - { - if (defaultDataDir != EMPTY_STRING) - { - m_dataDir = getValueOfDefaultDefine(); - if (!m_dataDir.empty()) - { - valSrcStr = "define"; - } - else if (defaultDataDir == DEFAULT_DEFINE_THEN_VIZ_FRAMEWORK) - { - m_dataDir = getVizFrameworkDefault(); - if (!m_dataDir.empty()) - { - valSrcStr = "vizFramework"; - } - } - } - } - - m_extraDataDir = Utils::getEnvironmentVar("CVF_UTEST_EXTRA_DATA_DIR"); - - if (verbose) - { - printf("\n"); - printf("dataDir : \"%s\" [src=%s]\n", m_dataDir.c_str(), valSrcStr.c_str()); - printf("extraDir: \"%s\"\n", m_extraDataDir.c_str()); - } - - m_isInitialized = true; - } - - // Extract value set via compile time define - static std::string getValueOfDefaultDefine() - { - std::string defDataDir; -#ifdef CVF_UTEST_DEFAULT_DATA_DIR - defDataDir = CVF_UTEST_DEFAULT_DATA_DIR; -#endif - return defDataDir; - } - - // Determine VizFramework default based on executable path and our fixed dir structure - static std::string getVizFrameworkDefault() - { - std::string exe = Utils::getMyExecutablePath(); - std::string dataDir; -#ifdef WIN32 - dataDir = exe.substr(0, exe.find("VizFwk\\")) + std::string("VizFwk\\Tests\\TestData\\"); -#else - dataDir = exe.substr(0, exe.find("VizFwk/")) + std::string("VizFwk/Tests/TestData/"); -#endif - return dataDir; - } - - static TestDataDir* internalInstance() - { - static TestDataDir sl_theInstance; - return &sl_theInstance; - } - -private: - bool m_isInitialized; - std::string m_dataDir; // The primary data directory - std::string m_extraDataDir; // Optional extra data dir, settable only via environment variable -}; - - }