Fix up linux build.

This commit is contained in:
James Grogan 2023-01-16 12:36:02 +00:00
parent c81db288b0
commit b76dc184b3
21 changed files with 86 additions and 66 deletions

View file

@ -11,24 +11,24 @@ class LineNode;
class BlochSphereNode : public AbstractVisualNode class BlochSphereNode : public AbstractVisualNode
{ {
public: public:
BlochSphereNode(const Point& location); BlochSphereNode(const Point& location);
void setContent(BlochSphere* content); void setContent(BlochSphere* content);
void update(SceneInfo* sceneInfo) override; void update(SceneInfo* sceneInfo) override;
void setSize(double size); void setSize(double size);
private: private:
double mSize{ 1.0 }; double mSize{ 1.0 };
bool mContentDirty{ true }; bool mContentDirty{ true };
BlochSphere* mContent{ nullptr }; BlochSphere* mContent{ nullptr };
std::unique_ptr<CircleNode> mOuterCircle; std::unique_ptr<CircleNode> mOuterCircle;
std::unique_ptr<CircleNode> mInnerCircle; std::unique_ptr<CircleNode> mInnerCircle;
std::unique_ptr<CircleNode> mCentreCircle; std::unique_ptr<CircleNode> mCentreCircle;
std::unique_ptr<CircleNode> mStateMarkerCircle; std::unique_ptr<CircleNode> mStateMarkerCircle;
std::unique_ptr<LineNode> mXAxis; std::unique_ptr<LineNode> mXAxis;
std::unique_ptr<LineNode> mYAxis; std::unique_ptr<LineNode> mYAxis;
std::unique_ptr<LineNode> mZAxis; std::unique_ptr<LineNode> mZAxis;
std::unique_ptr<LineNode> mStateVector; std::unique_ptr<LineNode> mStateVector;
}; };

View file

@ -3,21 +3,23 @@
#include "TestRenderUtils.h" #include "TestRenderUtils.h"
#include "BlochSphereNode.h" #include "BlochSphereNode.h"
#include "CircleNode.h"
#include "LineNode.h"
#include "BlochSphere.h" #include "BlochSphere.h"
TEST_CASE(TestBlochSphereNode, "quantum_computing") TEST_CASE(TestBlochSphereNode, "quantum_computing")
{ {
TestRenderer renderer(100, 100); TestRenderer renderer(100, 100);
auto node = std::make_unique<BlochSphereNode>(Point(0.5, 0.5)); auto node = std::make_unique<BlochSphereNode>(Point(0.5, 0.5));
Qubit state({ 1.0, 0.0 }, { 0.0, 0.0 }); Qubit state({ 1.0, 0.0 }, { 0.0, 0.0 });
auto bloch_sphere = std::make_unique<BlochSphere>(state); auto bloch_sphere = std::make_unique<BlochSphere>(state);
node->setSize(100);
node->setContent(bloch_sphere.get());
renderer.getScene()->addNode(node.get()); node->setSize(100);
renderer.writeSvg(TestUtils::getTestOutputDir(__FILE__) / "bloch_sphere.svg"); node->setContent(bloch_sphere.get());
}
renderer.getScene()->addNode(node.get());
renderer.writeSvg(TestUtils::getTestOutputDir(__FILE__) / "bloch_sphere.svg");
}

View file

@ -3,6 +3,7 @@
#include "Win32BaseIncludes.h" #include "Win32BaseIncludes.h"
#include <vector> #include <vector>
#include <stdexcept>
std::string UnicodeUtils::utf16ToUtf8String(const std::wstring& input) std::string UnicodeUtils::utf16ToUtf8String(const std::wstring& input)
{ {
@ -37,4 +38,4 @@ std::wstring UnicodeUtils::utf8ToUtf16WString(const std::string& input)
#else #else
throw std::logic_error("Not implemented"); throw std::logic_error("Not implemented");
#endif #endif
} }

View file

@ -10,7 +10,7 @@
#include <fcntl.h> #include <fcntl.h>
#endif #endif
void SharedMemory::allocate(const std::string& namePrefix, std::size_t) void SharedMemory::allocate(const std::string& namePrefix, std::size_t size)
{ {
createFile(namePrefix); createFile(namePrefix);
@ -30,6 +30,8 @@ void SharedMemory::allocate(const std::string& namePrefix, std::size_t)
close(mFileDescriptor); close(mFileDescriptor);
mIsValid = false; mIsValid = false;
} }
#else
(void)(size);
#endif #endif
} }

View file

@ -1,6 +1,7 @@
#include "FreeTypeFontEngine.h" #include "FreeTypeFontEngine.h"
#include "Image.h" #include "Image.h"
#include "Grid.h"
#include "FileLogger.h" #include "FileLogger.h"
#include "FontGlyph.h" #include "FontGlyph.h"
@ -20,7 +21,7 @@ void FreeTypeFontEngine::initialize()
} }
} }
void FreeTypeFontEngine::loadFontFace(const std::filesystem::path& fontFile, int penSize) void FreeTypeFontEngine::loadFontFace(const std::filesystem::path& fontFile, float penSize)
{ {
if (!mLibrary) if (!mLibrary)
{ {
@ -78,7 +79,7 @@ std::unique_ptr<FontGlyph> FreeTypeFontEngine::loadGlyph(uint32_t charCode)
auto rows = mWorkingFontFace->glyph->bitmap.rows; auto rows = mWorkingFontFace->glyph->bitmap.rows;
auto columns = mWorkingFontFace->glyph->bitmap.width; auto columns = mWorkingFontFace->glyph->bitmap.width;
auto image = std::make_unique<Image<unsigned char>> (columns, rows); auto image = std::make_unique<Image>(columns, rows);
unsigned counter = 0; unsigned counter = 0;
std::vector<unsigned char> data(rows*columns, 0); std::vector<unsigned char> data(rows*columns, 0);
@ -90,7 +91,7 @@ std::unique_ptr<FontGlyph> FreeTypeFontEngine::loadGlyph(uint32_t charCode)
counter++; counter++;
} }
} }
image->setData(data); image->getGridT<unsigned char>()->setData(data);
auto glyph = std::make_unique<FontGlyph>(mWorkingFontFace->glyph->bitmap.width, auto glyph = std::make_unique<FontGlyph>(mWorkingFontFace->glyph->bitmap.width,
mWorkingFontFace->glyph->bitmap.rows, mWorkingFontFace->glyph->bitmap.rows,
mWorkingFontFace->glyph->bitmap_left, mWorkingFontFace->glyph->bitmap_left,

View file

@ -4,7 +4,6 @@
#include "Image.h" #include "Image.h"
template<typename T>
class Image; class Image;
#include <ft2build.h> #include <ft2build.h>
@ -17,7 +16,7 @@ public:
void initialize() override; void initialize() override;
void loadFontFace(const std::filesystem::path& fontFile, int penSize = 16) override; void loadFontFace(const std::filesystem::path& fontFile, float penSize = 16) override;
std::unique_ptr<FontGlyph> loadGlyph(uint32_t charCode) override; std::unique_ptr<FontGlyph> loadGlyph(uint32_t charCode) override;

View file

@ -9,16 +9,22 @@ template <typename T>
class TypedGrid : public AbstractGrid class TypedGrid : public AbstractGrid
{ {
public: public:
TypedGrid(const Bounds& bounds, std::size_t numPointsX, std::size_t numPointsY, std::size_t numPointsZ = 1) TypedGrid(const Bounds& bounds, std::size_t numPointsX, std::size_t numPointsY, std::size_t numPointsZ = 1)
: AbstractGrid(bounds, numPointsX, numPointsY, numPointsZ), : AbstractGrid(bounds, numPointsX, numPointsY, numPointsZ),
mData(std::make_unique<List<T> >()) mData(std::make_unique<List<T> >())
{ {
} }
virtual T getItem(std::size_t idx, std::size_t jdx, std::size_t kdx) const = 0; virtual ~TypedGrid() = default;
virtual void setItem(std::size_t idx, std::size_t jdx, std::size_t kdx, const T& value) = 0; virtual T getItem(std::size_t idx, std::size_t jdx, std::size_t kdx) const = 0;
virtual void setItem(std::size_t idx, std::size_t jdx, std::size_t kdx, const T& value) = 0;
List<T>* getInternalData() const
{
return mData.get();
}
protected: protected:
std::unique_ptr<List<T> > mData; std::unique_ptr<List<T> > mData;
}; };

View file

@ -1,6 +1,7 @@
#include "OpenGlFontTexture.h" #include "OpenGlFontTexture.h"
#include "FontGlyph.h" #include "FontGlyph.h"
#include "Grid.h"
#include "Image.h" #include "Image.h"
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES
@ -14,7 +15,7 @@ OpenGlFontTexture::OpenGlFontTexture(FontGlyph* glyph)
glGenTextures(1, &mHandle); glGenTextures(1, &mHandle);
glBindTexture(GL_TEXTURE_2D, mHandle); glBindTexture(GL_TEXTURE_2D, mHandle);
auto buffer = glyph->getImage()->getDataPtr(); auto buffer = glyph->getImage()->getGridT<unsigned char>()->getInternalData()->getDataPtr();
glTexImage2D( glTexImage2D(
GL_TEXTURE_2D, GL_TEXTURE_2D,

View file

@ -45,7 +45,7 @@ void OpenGlMeshPainter::initializeBuffers()
glGenVertexArrays(1, &mVertexArray); glGenVertexArrays(1, &mVertexArray);
} }
void OpenGlMeshPainter::paint(const std::vector<float>& verts, const std::vector<unsigned>& elements, const std::vector<float>& color, bool lines) void OpenGlMeshPainter::paint(const std::vector<float>& verts, const std::vector<std::size_t>& elements, const std::vector<float>& color, bool lines)
{ {
glBindVertexArray(mVertexArray); glBindVertexArray(mVertexArray);
@ -113,7 +113,7 @@ void OpenGlMeshPainter::paint(SceneModel* model, DrawingContext* context)
} }
std::vector<unsigned> indices; std::vector<std::size_t> indices;
const bool line_mesh = model->getMesh()->getType() == AbstractMesh::MeshType::LINE; const bool line_mesh = model->getMesh()->getType() == AbstractMesh::MeshType::LINE;
if (line_mesh) if (line_mesh)
{ {
@ -124,7 +124,7 @@ void OpenGlMeshPainter::paint(SceneModel* model, DrawingContext* context)
indices = dynamic_cast<TriMesh*>(model->getMesh())->getFaceNodeIds(); indices = dynamic_cast<TriMesh*>(model->getMesh())->getFaceNodeIds();
} }
auto model_color = model->getColor().getAsVectorDouble(); auto model_color = model->getFillColor().getAsVectorDouble();
std::vector<float> color = {float(model_color[0]), float(model_color[1]), float(model_color[2]), float(model_color[3])}; std::vector<float> color = {float(model_color[0]), float(model_color[1]), float(model_color[2]), float(model_color[3])};
paint(vertices, indices, color, line_mesh); paint(vertices, indices, color, line_mesh);

View file

@ -18,7 +18,7 @@ private:
void initializeShader(); void initializeShader();
void initializeBuffers(); void initializeBuffers();
void paint(const std::vector<float>& verts, const std::vector<unsigned>& elements, const std::vector<float>& color, bool lines = false); void paint(const std::vector<float>& verts, const std::vector<std::size_t>& elements, const std::vector<float>& color, bool lines = false);
unsigned mVertexBuffer{0}; unsigned mVertexBuffer{0};
unsigned mElementBuffer{0}; unsigned mElementBuffer{0};

View file

@ -32,7 +32,7 @@
#include <iostream> #include <iostream>
OpenGlPainter::OpenGlPainter(DrawingContext* context) OpenGlPainter::OpenGlPainter(DrawingContext* context)
: AbstractPainter(context) : AbstractPainter(context),
mMeshPainter(std::make_unique<OpenGlMeshPainter>()), mMeshPainter(std::make_unique<OpenGlMeshPainter>()),
mTextPainter(std::make_unique<OpenGlTextPainter>()) mTextPainter(std::make_unique<OpenGlTextPainter>())
{ {
@ -41,7 +41,7 @@ OpenGlPainter::OpenGlPainter(DrawingContext* context)
void OpenGlPainter::paint() void OpenGlPainter::paint()
{ {
auto surface = context->getSurface(); auto surface = mDrawingContext->getSurface();
const auto width = double(surface->getWidth()); const auto width = double(surface->getWidth());
const auto height = double(surface->getHeight()); const auto height = double(surface->getHeight());

View file

@ -84,7 +84,9 @@ PlatformImage* Image::getPlatformImage()
{ {
if (!mPlatformImage) if (!mPlatformImage)
{ {
#ifdef _WIN32
mPlatformImage = std::make_unique<Win32WicImage>(this); mPlatformImage = std::make_unique<Win32WicImage>(this);
#endif
} }
return mPlatformImage.get(); return mPlatformImage.get();
} }

View file

@ -20,7 +20,7 @@ class BasicPngWriter : public IImageWriter
public: public:
BasicPngWriter(); BasicPngWriter();
~BasicPngWriter(); virtual ~BasicPngWriter();
static std::unique_ptr<BasicPngWriter> Create(); static std::unique_ptr<BasicPngWriter> Create();
@ -49,4 +49,4 @@ private:
PngHeader mPngHeader; PngHeader mPngHeader;
Deflate::CompressionMethod mCompressionMethod{ Deflate::CompressionMethod::DYNAMIC_HUFFMAN }; Deflate::CompressionMethod mCompressionMethod{ Deflate::CompressionMethod::DYNAMIC_HUFFMAN };
}; };

View file

@ -12,7 +12,7 @@ PngWriter::PngWriter()
#ifdef _WIN32 #ifdef _WIN32
mWriterImpl = std::make_unique<Win32WicImageWriter>(mFormat); mWriterImpl = std::make_unique<Win32WicImageWriter>(mFormat);
#else #else
mWriterImpl = std::make_unique<BasicPngWriter>(mFormat); mWriterImpl = std::make_unique<BasicPngWriter>();
#endif #endif
} }
@ -29,4 +29,4 @@ std::unique_ptr<PngWriter> PngWriter::Create()
void PngWriter::write(const Path& path, Image* image) void PngWriter::write(const Path& path, Image* image)
{ {
mWriterImpl->write(path, image); mWriterImpl->write(path, image);
} }

View file

@ -61,7 +61,8 @@ void AbstractMesh::transform(const Transform& transform)
void AbstractMesh::translate(double offsetX, double offsetY, double offsetZ) void AbstractMesh::translate(double offsetX, double offsetY, double offsetZ)
{ {
Transform transform({ -offsetX, -offsetY, -offsetZ }); const Point loc {-offsetX, -offsetY, -offsetZ};
Transform transform(loc);
for (auto& node : mNodes) for (auto& node : mNodes)
{ {
node->apply(transform); node->apply(transform);

View file

@ -40,7 +40,7 @@ void NetworkManager::runHttpServer(AbstractWebApp* webApp)
#else #else
if (!mSocketInterface) if (!mSocketInterface)
{ {
Initialize(); initialize();
} }
auto socket = Socket::Create(); auto socket = Socket::Create();

View file

@ -3,6 +3,7 @@
#include <xcb/xcb_image.h> #include <xcb/xcb_image.h>
#include "Window.h" #include "Window.h"
#include "Grid.h"
#include "XcbWindow.h" #include "XcbWindow.h"
#include "Image.h" #include "Image.h"
@ -28,7 +29,7 @@ public:
const auto h = window->getHeight(); const auto h = window->getHeight();
//auto data = const_cast<unsigned char*>(backing_image->getDataPtr()); //auto data = const_cast<unsigned char*>(backing_image->getDataPtr());
auto data = backing_image->getData(); auto data = backing_image->getGridT<unsigned char>()->getInternalData()->getData();
unsigned char* converted = &data[0]; unsigned char* converted = &data[0];
mXImage = xcb_image_create_native(connection, w, h, XCB_IMAGE_FORMAT_Z_PIXMAP, screen->root_depth, converted, w*h*4, converted); mXImage = xcb_image_create_native(connection, w, h, XCB_IMAGE_FORMAT_Z_PIXMAP, screen->root_depth, converted, w*h*4, converted);

View file

@ -46,8 +46,8 @@ namespace {
} _xkb_event; } _xkb_event;
} }
XcbInterface::XcbInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware) XcbInterface::XcbInterface(DesktopManager* desktopManager, bool useHardware)
: AbstractUIInterface(desktopManager, std::move(fontsManager), useHardware), : AbstractUIInterface(desktopManager, useHardware),
mEventInterface(XcbEventInterface::Create()), mEventInterface(XcbEventInterface::Create()),
mExtensionInterface(std::make_unique<XcbExtensionInterface>()) mExtensionInterface(std::make_unique<XcbExtensionInterface>())
{ {
@ -177,7 +177,7 @@ uint32_t XcbInterface::getEventMask()
void XcbInterface::addWindow(mt::Window* window) void XcbInterface::addWindow(mt::Window* window)
{ {
auto screen = mDesktopManager->getDefaultScreen(); auto screen = mDesktopManager->getDefaultScreen();
XcbWindow::add(window, mConnection, screen, getEventMask(), mFontsManager.get(), mGlInterface.get()); XcbWindow::add(window, mConnection, screen, getEventMask(), mDesktopManager->getFontsManager(), mGlInterface.get());
} }
void XcbInterface::onPaint() void XcbInterface::onPaint()

View file

@ -27,7 +27,7 @@ namespace mt
class XcbInterface : public AbstractUIInterface class XcbInterface : public AbstractUIInterface
{ {
public: public:
XcbInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware = true); XcbInterface(DesktopManager* desktopManager, bool useHardware = true);
~XcbInterface(); ~XcbInterface();

View file

@ -69,7 +69,7 @@ void XcbWindow::add(mt::Window* window, xcb_connection_t* connection, mt::Screen
auto xcb_window = std::make_unique<XcbWindow>(window, hwnd, connection, xcbGlInterface); auto xcb_window = std::make_unique<XcbWindow>(window, hwnd, connection, xcbGlInterface);
const auto drawing_mode = xcbGlInterface ? DrawingMode::GRAPH : DrawingMode::RASTER; const auto drawing_mode = xcbGlInterface ? DrawingMode::GRAPH : DrawingMode::RASTER;
window->setPlatformWindow(std::move(xcb_window), fontsManager, drawing_mode); window->setPlatformWindow(std::move(xcb_window));
} }
int XcbWindow::getHandle() const int XcbWindow::getHandle() const

View file

@ -19,9 +19,9 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
std::cout.rdbuf(out.rdbuf()); std::cout.rdbuf(out.rdbuf());
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
auto args = CommandLineArgs::Create(); auto args = CommandLineArgs::Create();
CommandLineArgs::initialize(args.get()); CommandLineArgs::initialize(args.get());
const auto user_args = args->getUserArgs(); const auto user_args = args->getUserArgs();
@ -34,12 +34,16 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
main_app->initialize(std::move(args), std::move(applicationContext)); main_app->initialize(std::move(args), std::move(applicationContext));
auto gui_app = std::make_unique<TestUiApplication>(nullptr, std::move(main_app)); auto gui_app = std::make_unique<TestUiApplication>(nullptr, std::move(main_app));
#else #else
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
auto args = CommandLineArgs::Create(); auto args = CommandLineArgs::Create();
args->process(argc, argv); args->process(argc, argv);
auto user_args = args->getArgs();
auto gui_app = std::make_unique<TestUiApplication>(std::move(args));
#endif #endif
TestCaseRunner::getInstance().setTestApplication(gui_app.get()); TestCaseRunner::getInstance().setTestApplication(gui_app.get());