src/gl/basicshaderprogram.h

Mon, 09 Mar 2020 14:21:54 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 09 Mar 2020 14:21:54 +0200
changeset 73
97df974b5ed5
parent 70
f21b800b02a4
child 75
204dc77e5654
permissions
-rw-r--r--

ldraw::Id is now templated for extra type safety

#pragma once
#include "common.h"

class AbstractBasicShaderProgram : public QObject, protected QOpenGLFunctions
{
	Q_OBJECT
public:
	AbstractBasicShaderProgram(QObject* parent = nullptr);
	~AbstractBasicShaderProgram() = default;
	void initialize();
	Q_SLOT void setViewMatrix(const glm::mat4& newViewMatrix);
	Q_SLOT void setProjectionMatrix(const glm::mat4& newProjectionMatrix);
	Q_SLOT void setModelMatrix(const glm::mat4& newModelMatrix);
	void draw();
	void teardown();
protected:
	void setMatrix(const char* name, const glm::mat4& matrix);
	void checkForGLErrors();
	virtual const char* vertexShaderSource() const = 0;
	virtual const char* fragmentShaderSource() const = 0;
	virtual const void* vertexData() const = 0;
	virtual int vertexSize() const = 0;
	virtual int vertexCount() const = 0;
	virtual void setupVertexArrays() = 0;
	virtual GLenum drawMode() const = 0;
	bool isInitialized = false;
	QOpenGLBuffer buffer;
	QOpenGLShader vertexShader;
	QOpenGLShader fragmentShader;
	std::optional<gl::ShaderProgram> program{std::nullopt};
	QOpenGLVertexArrayObject vertexArrayObject;
};

mercurial