Cleaning for opengl rendering prep.
This commit is contained in:
parent
402f381d10
commit
7c6a92f4ec
58 changed files with 570 additions and 533 deletions
10
src/graphics/AbstractPainter.h
Normal file
10
src/graphics/AbstractPainter.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
class DrawingContext;
|
||||
|
||||
class AbstractPainter
|
||||
{
|
||||
public:
|
||||
virtual ~AbstractPainter() = default;
|
||||
virtual void paint(DrawingContext* context) = 0;
|
||||
};
|
|
@ -7,23 +7,21 @@ list(APPEND graphics_LIB_INCLUDES
|
|||
DrawingContext.cpp
|
||||
DrawingManager.cpp
|
||||
DrawingSurface.cpp
|
||||
Rasterizer.cpp
|
||||
RasterPainter.cpp
|
||||
${platform_LIB_INCLUDES}
|
||||
)
|
||||
|
||||
list(APPEND graphics_HEADERS
|
||||
${platform_HEADERS}
|
||||
Rasterizer.h
|
||||
INativeDrawingSurface.h
|
||||
INativeDrawingContext.h
|
||||
RasterPainter.h
|
||||
)
|
||||
|
||||
set(OpenGL_GL_PREFERENCE "GLVND")
|
||||
find_package(OpenGL QUIET)
|
||||
if (OpenGL_FOUND)
|
||||
list(APPEND platform_LIBS OpenGL::GL)
|
||||
list(APPEND graphics_LIB_INCLUDES opengl/OpenGlInterface.cpp)
|
||||
list(APPEND graphics_HEADERS opengl/OpenGlInterface.h)
|
||||
list(APPEND graphics_LIB_INCLUDES opengl/OpenGlPainter.cpp)
|
||||
list(APPEND graphics_HEADERS opengl/OpenGlPainter.h)
|
||||
else()
|
||||
message(STATUS "OpenGL headers not found - skipping OpenGL support")
|
||||
endif()
|
||||
|
@ -35,11 +33,7 @@ add_library(graphics SHARED
|
|||
target_include_directories(graphics PUBLIC
|
||||
${platform_INCLUDE_DIRS}
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cairo"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/opengl"
|
||||
"${PROJECT_SOURCE_DIR}/src/geometry/"
|
||||
"${PROJECT_SOURCE_DIR}/src/image/"
|
||||
"${PROJECT_SOURCE_DIR}/src/visual_elements/"
|
||||
)
|
||||
|
||||
target_link_libraries(graphics PUBLIC visual_elements image ${platform_LIBS})
|
||||
|
|
|
@ -1,43 +1,53 @@
|
|||
#include "DrawingContext.h"
|
||||
|
||||
#include "INativeDrawingContext.h"
|
||||
#include "AbstractGeometricItem.h"
|
||||
#include "AbstractPainter.h"
|
||||
#include "OpenGlPainter.h"
|
||||
#include "RasterPainter.h"
|
||||
#include "DrawingSurface.h"
|
||||
#include "Scene.h"
|
||||
#include "Grid.h"
|
||||
|
||||
#include "MeshBuilder.h"
|
||||
|
||||
#include "TriMesh.h"
|
||||
|
||||
std::unique_ptr<DrawingContext> DrawingContext::Create()
|
||||
DrawingContext::DrawingContext(DrawingSurface* surface, DrawingMode requestedDrawingMode)
|
||||
: mSurface(surface),
|
||||
mDrawingMode(requestedDrawingMode),
|
||||
mScene(std::make_unique<Scene>())
|
||||
{
|
||||
return std::make_unique<DrawingContext>();
|
||||
if (mDrawingMode == DrawingMode::GRAPH)
|
||||
{
|
||||
mPainter = std::make_unique<OpenGlPainter>();
|
||||
}
|
||||
else
|
||||
{
|
||||
mPainter = std::make_unique<RasterPainter>();
|
||||
}
|
||||
}
|
||||
|
||||
void DrawingContext::setNativeContext(std::unique_ptr<INativeDrawingContext> context)
|
||||
std::unique_ptr<DrawingContext> DrawingContext::Create(DrawingSurface* surface, DrawingMode requestedDrawingMode)
|
||||
{
|
||||
mNativeDrawingContext = std::move(context);
|
||||
}
|
||||
|
||||
INativeDrawingContext* DrawingContext::getNativeContext()
|
||||
{
|
||||
return mNativeDrawingContext.get();
|
||||
}
|
||||
|
||||
void DrawingContext::addDrawable(AbstractGeometricItemPtr item)
|
||||
{
|
||||
mItems.push_back(std::move(item));
|
||||
}
|
||||
|
||||
unsigned DrawingContext::getNumItems() const
|
||||
{
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
AbstractGeometricItem* DrawingContext::getDrawable(unsigned idx) const
|
||||
{
|
||||
return mItems[idx].get();
|
||||
return std::make_unique<DrawingContext>(surface, requestedDrawingMode);
|
||||
}
|
||||
|
||||
void DrawingContext::updateMesh()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Scene* DrawingContext::getScene() const
|
||||
{
|
||||
return mScene.get();
|
||||
}
|
||||
|
||||
DrawingSurface* DrawingContext::getSurface() const
|
||||
{
|
||||
return mSurface;
|
||||
}
|
||||
|
||||
void DrawingContext::paint()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -3,35 +3,38 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class INativeDrawingContext;
|
||||
class AbstractGeometricItem;
|
||||
using AbstractGeometricItemPtr = std::unique_ptr<AbstractGeometricItem>;
|
||||
|
||||
class Scene;
|
||||
class AbstractPainter;
|
||||
class DrawingSurface;
|
||||
class TriMesh;
|
||||
|
||||
enum class DrawingMode
|
||||
{
|
||||
RASTER,
|
||||
GRAPH
|
||||
};
|
||||
|
||||
class DrawingContext
|
||||
{
|
||||
public:
|
||||
DrawingContext() = default;
|
||||
DrawingContext(DrawingSurface* surface, DrawingMode requestedDrawingMode);
|
||||
|
||||
static std::unique_ptr<DrawingContext> Create();
|
||||
static std::unique_ptr<DrawingContext> Create(DrawingSurface* surface, DrawingMode requestedDrawingMode);
|
||||
|
||||
void setNativeContext(std::unique_ptr<INativeDrawingContext> context);
|
||||
Scene* getScene() const;
|
||||
|
||||
INativeDrawingContext* getNativeContext();
|
||||
DrawingSurface* getSurface() const;
|
||||
|
||||
unsigned getNumItems() const;
|
||||
|
||||
void addDrawable(AbstractGeometricItemPtr item);
|
||||
|
||||
AbstractGeometricItem* getDrawable(unsigned idx) const;
|
||||
void paint();
|
||||
|
||||
private:
|
||||
void updateMesh();
|
||||
|
||||
DrawingMode mDrawingMode;
|
||||
std::unique_ptr<TriMesh> mMesh;
|
||||
std::vector<std::unique_ptr<AbstractGeometricItem> > mItems;
|
||||
std::unique_ptr<INativeDrawingContext> mNativeDrawingContext;
|
||||
std::unique_ptr<Scene> mScene;
|
||||
DrawingSurface* mSurface{nullptr};
|
||||
std::unique_ptr<AbstractPainter> mPainter;
|
||||
};
|
||||
|
||||
using DrawingContextPtr = std::unique_ptr<DrawingContext>;
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
#include "DrawingManager.h"
|
||||
|
||||
#include "INativeDrawingContext.h"
|
||||
#include "DrawingSurface.h"
|
||||
#include "DrawingContext.h"
|
||||
#include "Rasterizer.h"
|
||||
#include "AbstractPainter.h"
|
||||
|
||||
#include "Grid.h"
|
||||
#include "Image.h"
|
||||
#include "TriMesh.h"
|
||||
#include "Scene.h"
|
||||
|
||||
DrawingManager::DrawingManager()
|
||||
: mRasterizer(std::make_unique<Rasterizer>())
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -23,12 +22,12 @@ std::unique_ptr<DrawingManager> DrawingManager::Create()
|
|||
void DrawingManager::InitalizeSurface(unsigned width, unsigned height)
|
||||
{
|
||||
mDrawingSurface = DrawingSurface::Create();
|
||||
mDrawingSurface->SetSize(width, height);
|
||||
mDrawingSurface->setSize(width, height);
|
||||
}
|
||||
|
||||
void DrawingManager::InitializeContext()
|
||||
{
|
||||
mDrawingContext = DrawingContext::Create();
|
||||
//mDrawingContext = DrawingContext::Create();
|
||||
}
|
||||
|
||||
void DrawingManager::AddText(TextNode* text)
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "INativeDrawingContext.h"
|
||||
#include "INativeDrawingSurface.h"
|
||||
|
||||
class TextNode;
|
||||
|
||||
|
@ -12,8 +10,6 @@ using DrawingSurfacePtr = std::unique_ptr<DrawingSurface>;
|
|||
class DrawingContext;
|
||||
using DrawingContextPtr = std::unique_ptr<DrawingContext>;
|
||||
|
||||
class Rasterizer;
|
||||
|
||||
class DrawingManager
|
||||
{
|
||||
public:
|
||||
|
@ -25,7 +21,6 @@ public:
|
|||
void RenderToFile(const std::string& path);
|
||||
|
||||
private:
|
||||
std::unique_ptr<Rasterizer> mRasterizer;
|
||||
DrawingSurfacePtr mDrawingSurface {nullptr};
|
||||
DrawingContextPtr mDrawingContext {nullptr};
|
||||
};
|
||||
|
|
|
@ -7,40 +7,28 @@ std::unique_ptr<DrawingSurface> DrawingSurface::Create()
|
|||
return std::make_unique<DrawingSurface>();
|
||||
}
|
||||
|
||||
INativeDrawingSurface* DrawingSurface::GetNativeSurface()
|
||||
{
|
||||
if (mNativeDrawingSurface)
|
||||
{
|
||||
return mNativeDrawingSurface.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void DrawingSurface::SetNativeSurface(std::unique_ptr<INativeDrawingSurface> surface)
|
||||
{
|
||||
mNativeDrawingSurface = std::move(surface);
|
||||
}
|
||||
|
||||
void DrawingSurface::SetSize(unsigned width, unsigned height)
|
||||
void DrawingSurface::setSize(unsigned width, unsigned height)
|
||||
{
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
}
|
||||
|
||||
unsigned DrawingSurface::GetWidth() const
|
||||
unsigned DrawingSurface::getWidth() const
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
unsigned DrawingSurface::GetHeight() const
|
||||
unsigned DrawingSurface::getHeight() const
|
||||
{
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
void DrawingSurface::Paint(Grid* grid)
|
||||
Image<unsigned char>* DrawingSurface::getImage()
|
||||
{
|
||||
//mImageBuffer = std::make_unique<Image>();
|
||||
if (!mBackingImage)
|
||||
{
|
||||
mBackingImage = std::make_unique<Image<unsigned char> >(mWidth, mHeight);
|
||||
mBackingImage->initialize();
|
||||
}
|
||||
return mBackingImage.get();
|
||||
}
|
||||
|
|
|
@ -2,36 +2,27 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
#include "INativeDrawingSurface.h"
|
||||
#include "Image.h"
|
||||
|
||||
class Grid;
|
||||
template<typename T>
|
||||
class Image;
|
||||
|
||||
class DrawingSurface
|
||||
{
|
||||
public:
|
||||
DrawingSurface() = default;
|
||||
virtual ~DrawingSurface() = default;
|
||||
|
||||
static std::unique_ptr<DrawingSurface> Create();
|
||||
|
||||
INativeDrawingSurface* GetNativeSurface();
|
||||
void setSize(unsigned width, unsigned height);
|
||||
|
||||
void SetNativeSurface(std::unique_ptr<INativeDrawingSurface> surface);
|
||||
unsigned getWidth() const;
|
||||
|
||||
void SetSize(unsigned width, unsigned height);
|
||||
unsigned getHeight() const;
|
||||
|
||||
unsigned GetWidth() const;
|
||||
|
||||
unsigned GetHeight() const;
|
||||
|
||||
void Paint(Grid* grid);
|
||||
|
||||
Image<unsigned char>* GetAsImage() const;
|
||||
|
||||
private:
|
||||
Image<unsigned char>* getImage();
|
||||
|
||||
protected:
|
||||
unsigned mWidth = 0;
|
||||
unsigned mHeight = 0;
|
||||
std::unique_ptr<Image<unsigned char> > mImageBuffer;
|
||||
std::unique_ptr<INativeDrawingSurface> mNativeDrawingSurface;
|
||||
std::unique_ptr<Image<unsigned char> > mBackingImage;
|
||||
};
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
class INativeDrawingContext
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~INativeDrawingContext() = default;
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
class INativeDrawingSurface
|
||||
{
|
||||
public:
|
||||
virtual ~INativeDrawingSurface() = default;
|
||||
|
||||
virtual void DestroyNativeSurface() = 0;
|
||||
};
|
27
src/graphics/RasterPainter.cpp
Normal file
27
src/graphics/RasterPainter.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "RasterPainter.h"
|
||||
|
||||
#include "DrawingSurface.h"
|
||||
#include "DrawingContext.h"
|
||||
#include "Grid.h"
|
||||
|
||||
RasterPainter::RasterPainter()
|
||||
: mGrid(std::make_unique<Grid<unsigned char> >(Rectangle(Point(0, 0), Point(100, 100))))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RasterPainter::paint(DrawingContext* context)
|
||||
{
|
||||
const auto width = context->getSurface()->getWidth();
|
||||
const auto height = context->getSurface()->getHeight();
|
||||
mGrid->resetBounds(Rectangle(Point(0, 0), Point(width, height)));
|
||||
|
||||
/*
|
||||
for (unsigned idx=0; idx< context->getNumItems(); idx++)
|
||||
{
|
||||
context->getDrawable(idx)->sample(mGrid.get());
|
||||
}
|
||||
|
||||
context->getSurface()->getImage()->setData(mGrid->getValues());
|
||||
*/
|
||||
}
|
20
src/graphics/RasterPainter.h
Normal file
20
src/graphics/RasterPainter.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include "AbstractPainter.h"
|
||||
#include <memory>
|
||||
|
||||
class DrawingContext;
|
||||
|
||||
template<class T>
|
||||
class Grid;
|
||||
|
||||
class RasterPainter : public AbstractPainter
|
||||
{
|
||||
public:
|
||||
RasterPainter();
|
||||
|
||||
void paint(DrawingContext* context) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Grid<unsigned char> > mGrid;
|
||||
};
|
|
@ -1,25 +0,0 @@
|
|||
#include "Rasterizer.h"
|
||||
|
||||
#include "DrawingSurface.h"
|
||||
#include "DrawingContext.h"
|
||||
#include "Grid.h"
|
||||
|
||||
Rasterizer::Rasterizer()
|
||||
: mGrid(std::make_unique<Grid>(Rectangle(Point(0, 0), Point(100, 100))))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Rasterizer::Paint(DrawingSurface* surface, DrawingContext* context)
|
||||
{
|
||||
const auto width = surface->GetWidth();
|
||||
const auto height = surface->GetHeight();
|
||||
mGrid->ResetBounds(Rectangle(Point(0, 0), Point(width, height)));
|
||||
|
||||
for (unsigned idx=0; idx< context->getNumItems(); idx++)
|
||||
{
|
||||
context->getDrawable(idx)->Sample(mGrid.get());
|
||||
}
|
||||
|
||||
surface->Paint(mGrid.get());
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
class DrawingSurface;
|
||||
class DrawingContext;
|
||||
class Grid;
|
||||
|
||||
class Rasterizer
|
||||
{
|
||||
public:
|
||||
Rasterizer();
|
||||
|
||||
void Paint(DrawingSurface* surface, DrawingContext* context);
|
||||
|
||||
private:
|
||||
std::unique_ptr<Grid> mGrid;
|
||||
};
|
|
@ -1,11 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
class TriMesh;
|
||||
|
||||
class OpenGlInterface
|
||||
{
|
||||
public:
|
||||
static void draw(TriMesh* mesh);
|
||||
};
|
||||
|
||||
|
|
@ -1,11 +1,14 @@
|
|||
#include "OpenGlInterface.h"
|
||||
#include "OpenGlPainter.h"
|
||||
|
||||
#include "DrawingContext.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
void OpenGlInterface::draw(TriMesh* mesh)
|
||||
void OpenGlPainter::paint(DrawingContext* context)
|
||||
{
|
||||
glClearColor(0.4, 0.4, 0.4, 0.4);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
@ -13,8 +16,6 @@ void OpenGlInterface::draw(TriMesh* mesh)
|
|||
glColor3f(1.0, 1.0, 1.0);
|
||||
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
|
||||
|
||||
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
glVertex3f(-0.7, 0.7, 0);
|
||||
glVertex3f(0.7, 0.7, 0);
|
13
src/graphics/opengl/OpenGlPainter.h
Normal file
13
src/graphics/opengl/OpenGlPainter.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "AbstractPainter.h"
|
||||
|
||||
class DrawingContext;
|
||||
|
||||
class OpenGlPainter : public AbstractPainter
|
||||
{
|
||||
public:
|
||||
void paint(DrawingContext* context) override;
|
||||
};
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue