src/gl/partrenderer.h

Wed, 08 Jun 2022 23:02:04 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 08 Jun 2022 23:02:04 +0300
changeset 207
5315358a7d91
parent 206
654661eab7f3
child 215
34c6e7bc4ee1
permissions
-rw-r--r--

well that's embarrassing

#pragma once
#include <QOpenGLWidget>
#include "basics.h"
#include "gl/common.h"
#include "gl/compiler.h"
#include "documentmanager.h"
#include "types/boundingbox.h"

class PartRenderer : public QOpenGLWidget
{
	Q_OBJECT
public:
	PartRenderer(
		Model* model,
		DocumentManager* documents,
		const ColorTable& colorTable,
		QWidget* parent = nullptr);
	~PartRenderer() override;
	void setRenderPreferences(const gl::RenderPreferences& newPreferences);
	ModelId getHighlightedObject() const;
protected:
	ModelId pick(QPoint where);
	void initializeGL() override;
	void resizeGL(int width, int height) override;
	void paintGL() override;
	void mouseMoveEvent(QMouseEvent* event) override;
	void wheelEvent(QWheelEvent* event) override;
	Model* const model;
	DocumentManager* const documents;
	const ColorTable& colorTable;
	BoundingBox boundingBox;
	gl::ModelShaders shaders;
	ModelId highlighted = {0};
	std::optional<glm::vec3> screenToModelCoordinates(const QPointF &point, const Plane& plane) const;
	QPointF modelToScreenCoordinates(const glm::vec3& point) const;
	Line<3> cameraLine(const QPointF& point) const;
	glm::vec3 unproject(const glm::vec3& win) const;
	glm::mat4 projectionMatrix;
	glm::mat4 viewMatrix;
	glm::mat4 modelMatrix;
	glm::vec4 viewportVector;
	glm::quat modelQuaternion;
	QPoint lastMousePosition;
	gl::RenderPreferences renderPreferences;
Q_SIGNALS:
	void projectionMatrixChanged(const glm::mat4& newMatrix);
	void modelMatrixChanged(const glm::mat4& newMatrix);
	void viewMatrixChanged(const glm::mat4& newMatrix);
	void renderPreferencesChanged();
private:
	void setFragmentStyle(gl::FragmentStyle fragStyle);
	void renderScene();
	void updateViewMatrix();
	void updateModelMatrix();
	Q_SLOT void build();
	double zoom = 1.0;
	bool initialized = false;
	bool needBuild = true;
	void renderVao(const gl::ArrayClass arrayClass);
	void checkForGLErrors();
};

mercurial