Fixes to get snippets up and running before introducing new OpenGL widgets

This commit is contained in:
Sigurd Pettersen 2024-01-11 17:21:58 +01:00
parent 5cd3cb524d
commit f343427fc2
10 changed files with 85 additions and 191 deletions

View File

@ -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)
if (CEE_BUILD_TEST_APPS)
# For now, build the snippet libs here
add_subdirectory(Tests/SnippetsBasis)
endif()
if (CEE_BUILD_GUI_QT)
add_subdirectory(TestApps/Qt/QtMinimal_deprecated)
add_subdirectory(TestApps/Qt/QtMultiView_deprecated)
add_subdirectory(TestApps/Qt/QtSnippetRunner)
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()
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()

View File

@ -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<String> progArr = m_source.split("\n");
// for (size_t i = 0; i < progArr.size(); ++i)
// {
// errStr += String("%1: %2\n").arg(static_cast<int>(i + 1), 3).arg(progArr[i]);
// }
// }
CVF_LOG_RENDER_ERROR(oglContext, errStr);
return false;
}

View File

@ -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})

View File

@ -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;

View File

@ -1,2 +0,0 @@
Sole purpose of this file is to have custom build rules to trigger copying of TBB DLLs

View File

@ -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<cvfu::TestSnippet> snippet = SnippetRegistry::instance()->createSnippet("snip::MinimalModel");
//ref<cvfu::TestSnippet> snippet = SnippetRegistry::instance()->createSnippet("snip::Highlight");
ref<cvfu::TestSnippet> snippet = SnippetRegistry::instance()->createSnippet("snip::Stencil");
//ref<cvfu::TestSnippet> snippet = SnippetRegistry::instance()->createSnippet("snip::Stencil");
ref<cvfu::TestSnippet> snippet = SnippetRegistry::instance()->createSnippet("snip::TransparentWeightedAverage");
sl_snippetWnd = new Win32SnippetWindow;
sl_snippetWnd->create(hWnd, snippet.p());
SetFocus(sl_snippetWnd->windowHandle());

View File

@ -38,7 +38,7 @@
#include "cvfBase.h"
#include "gtest/gtest.h"
#include "gtest/cvftestUtils.h"
#include <stdio.h>
@ -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();
}

View File

@ -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<TextureImage> 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<TextureImage> 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<TextureImage> 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<TextureImage> img = ImageTga::loadImage(fullFileName);
ASSERT_TRUE(img.notNull());

View File

@ -252,13 +252,13 @@ ref<Part> 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" !\"#¤%&/()=?`^*@£$€{[]}´~¨',;.:+-_<>><VAWAVAA", cvf::Vec3f(50, 80, 0));
// m_textDrawable->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" !\"#¤%&/()=?`^*@£$€{[]}´~¨',;.:+-_<>><VAWAVAA", cvf::Vec3f(50, 80, 0));
m_textDrawable->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<RenderStateBlending> blending = new RenderStateBlending;

View File

@ -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 @@ public:
};
//==================================================================================================
//
// 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
};
}