First opengl/x11/window integration.

This commit is contained in:
James Grogan 2022-11-14 13:07:11 +00:00
parent 7c6a92f4ec
commit cea3d2c39f
30 changed files with 254 additions and 72 deletions

View file

@ -14,11 +14,18 @@ public:
}
virtual ~AbstractVisualNode() = default;
AbstractMesh* getMesh() const
{
return mMesh.get();
}
virtual void updateMesh()
{
}
Image<unsigned char>* getImage() const
{
return mImage.get();
@ -29,7 +36,7 @@ public:
return mLocation;
}
private:
protected:
DiscretePoint mLocation;
std::unique_ptr<AbstractMesh> mMesh;
std::unique_ptr<Image<unsigned char> > mImage;

View file

@ -1,5 +1,10 @@
#include "RectangleNode.h"
#include "Rectangle.h"
#include "MeshPrimitives.h"
#include <iostream>
RectangleNode::RectangleNode(const DiscretePoint& loc, unsigned width, unsigned height)
: GeometryNode(loc),
mWidth(width),
@ -27,3 +32,11 @@ unsigned RectangleNode::getHeight() const
{
return mHeight;
}
void RectangleNode::updateMesh()
{
const auto rect = Rectangle(mLocation, mWidth, mHeight);
auto mesh = MeshPrimitives::build(rect);
mMesh = std::move(mesh);
}

View file

@ -15,6 +15,8 @@ public:
unsigned getWidth() const;
unsigned getHeight() const;
void updateMesh() override;
private:
unsigned mWidth{1};
unsigned mHeight{1};

View file

@ -0,0 +1,54 @@
#include "Scene.h"
#include "VisualLayer.h"
#include "GeometryNode.h"
#include "RectangleNode.h"
#include "MeshBuilder.h"
#include "TriMesh.h"
void Scene::syncLayers(const std::vector<VisualLayer*>& layers)
{
mLayers = layers;
}
void Scene::update(Image<unsigned char>* image)
{
if (image)
{
//
}
else
{
mWorkingMeshs.clear();
for(auto layer : mLayers)
{
if (layer->hasShapeNode())
{
auto node = layer->getShapeNode();
if (layer->getIsDirty())
{
node->updateMesh();
layer->setIsDirty(false);
}
mWorkingMeshs.push_back(dynamic_cast<TriMesh*>(node->getMesh()));
}
}
}
}
void Scene::processRectangleNode(RectangleNode* node)
{
}
unsigned Scene::getNumMeshes() const
{
return mWorkingMeshs.size();
}
TriMesh* Scene::getMesh(std::size_t idx) const
{
return mWorkingMeshs[idx];
}

View file

@ -1,23 +1,33 @@
#pragma once
#include <vector>
#include <memory>
class VisualLayer;
class TriMesh;
class RectangleNode;
template <typename T>
class Image;
class Scene
{
public:
Scene() = default;
void setLayers(const std::vector<VisualLayer*>& layers)
{
mLayers = layers;
}
void syncLayers(const std::vector<VisualLayer*>& layers);
void update(Image<unsigned char>* image = nullptr);
unsigned getNumMeshes() const;
TriMesh* getMesh(std::size_t idx) const;
const std::vector<VisualLayer*>& getLayers() const
{
return mLayers;
}
private:
void processRectangleNode(RectangleNode* node);
std::vector<TriMesh*> mWorkingMeshs;
std::vector<VisualLayer*> mLayers;
};

View file

@ -15,32 +15,32 @@ std::unique_ptr<VisualLayer> VisualLayer::Create()
return std::make_unique<VisualLayer>();
}
bool VisualLayer::hasShape() const
bool VisualLayer::hasShapeNode() const
{
return bool(mShape);
}
bool VisualLayer::hasText() const
bool VisualLayer::hasTextNode() const
{
return bool(mText);
}
GeometryNode* VisualLayer::getShape() const
GeometryNode* VisualLayer::getShapeNode() const
{
return mShape.get();
}
TextNode* VisualLayer::getText() const
TextNode* VisualLayer::getTextNode() const
{
return mText.get();
}
void VisualLayer::setShape(GeometryNodePtr shape)
void VisualLayer::setShapeNode(GeometryNodePtr shape)
{
mShape = std::move(shape);
}
void VisualLayer::setText(std::unique_ptr<TextNode> text)
void VisualLayer::setTextNode(std::unique_ptr<TextNode> text)
{
mText = std::move(text);
}

View file

@ -12,14 +12,25 @@ public:
static std::unique_ptr<VisualLayer> Create();
GeometryNode* getShape() const;
TextNode* getText() const;
bool hasShape() const;
bool hasText() const;
void setShape(std::unique_ptr<GeometryNode> shape);
void setText(std::unique_ptr<TextNode> text);
GeometryNode* getShapeNode() const;
TextNode* getTextNode() const;
bool hasShapeNode() const;
bool hasTextNode() const;
void setShapeNode(std::unique_ptr<GeometryNode> shape);
void setTextNode(std::unique_ptr<TextNode> text);
bool getIsDirty() const
{
return mIsDirty;
}
void setIsDirty(bool isDirty)
{
mIsDirty = isDirty;
}
private:
bool mIsDirty{true};
std::unique_ptr<GeometryNode> mShape;
std::unique_ptr<TextNode> mText;
};