This commit is contained in:
2020-06-18 18:25:03 -06:00
commit e01c09fbcc
17 changed files with 2689 additions and 0 deletions

91
src/magnum_render.h Normal file
View File

@@ -0,0 +1,91 @@
#ifndef MAGNUM_RENDER_H
#define MAGNUM_RENDER_H
#include <Corrade/Containers/Optional.h>
#include <Magnum/GL/Framebuffer.h>
#include <Magnum/GL/Mesh.h>
#include <Magnum/Math/Vector2.h>
#include <Magnum/Platform/GLContext.h>
#include <Magnum/SceneGraph/Drawable.h>
#include <Magnum/SceneGraph/MatrixTransformation3D.h>
#include <Magnum/SceneGraph/Object.h>
#include <Magnum/SceneGraph/Scene.h>
#include <Magnum/Shaders/Flat.h>
#include <Magnum/Shaders/Phong.h>
#include "arc_ball_camera.h"
using namespace Magnum;
using Object3D = SceneGraph::Object<SceneGraph::MatrixTransformation3D>;
using Scene3D = SceneGraph::Scene<SceneGraph::MatrixTransformation3D>;
class MagnumRenderer {
public:
MagnumRenderer();
~MagnumRenderer();
void reset(Platform::GLContext *ctx,
GL::Framebuffer fbo,
Vector2i windowSize,
Vector2i viewportSize);
void render();
void t(float t);
void hue(float hue);
void count(int count);
private:
void lazyInitialize();
void prepGLState();
bool m_init{false};
float m_count{1};
Platform::GLContext *m_ctx;
GL::Framebuffer m_FBO{NoCreate};
Scene3D m_scene;
SceneGraph::DrawableGroup3D m_drawables;
Containers::Optional<ArcBallCamera> m_camera;
GL::Mesh m_subject{NoCreate};
Shaders::Phong m_subjectShader{NoCreate};
Object3D* m_subjectObject{nullptr};
GL::Mesh m_grid{NoCreate};
Shaders::Flat3D m_gridShader{NoCreate};
};
class GridDrawable : public SceneGraph::Drawable3D {
public:
explicit GridDrawable(Object3D &object, Shaders::Flat3D &shader,
GL::Mesh &mesh, SceneGraph::DrawableGroup3D &drawables)
: SceneGraph::Drawable3D{object, &drawables},
m_shader(shader),
m_mesh(mesh) {}
void draw(const Matrix4 &transformation, SceneGraph::Camera3D &camera);
private:
Shaders::Flat3D &m_shader;
GL::Mesh &m_mesh;
};
class SubjectDrawable : public SceneGraph::Drawable3D {
public:
explicit SubjectDrawable(Object3D &object, Shaders::Phong &shader,
GL::Mesh &mesh, SceneGraph::DrawableGroup3D &drawables)
: SceneGraph::Drawable3D{object, &drawables},
m_shader(shader),
m_mesh(mesh) {}
void draw(const Matrix4 &transformation, SceneGraph::Camera3D &camera);
private:
Shaders::Phong &m_shader;
GL::Mesh &m_mesh;
};
#endif // MAGNUM_RENDER_H