src/gl/partrenderer.h

Wed, 29 Jun 2022 16:33:49 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Wed, 29 Jun 2022 16:33:49 +0300
changeset 309
d862721d19a3
parent 291
42b4953dff85
child 313
c24d87f64bed
permissions
-rw-r--r--

Fixed ModelId being used to identify both models and elements, added ElementId to identify elements

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

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

mercurial