src/gl/basicshaderprogram.h

Tue, 28 Jun 2022 12:29:38 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 28 Jun 2022 12:29:38 +0300
changeset 283
96b7eb68e9e6
parent 264
76a025db4948
child 377
e1c5e4310f8b
permissions
-rw-r--r--

Make settings editor scrollable

#pragma once
#include "src/gl/common.h"

struct GLAttributeSpec
{
	GLenum type;
	int offset;
	int tuplesize;
	int stride;
};

//! @brief A collection of a single VAO with a single VBO,
//! a vertex shader and a fragment shader.
class BasicShader final
{
	bool isInitialized = false;
	QOpenGLBuffer buffer;
	QOpenGLShader vertexShader;
	QOpenGLShader fragmentShader;
	std::unique_ptr<gl::ShaderProgram> program = nullptr;
	QOpenGLVertexArrayObject vertexArrayObject;
	int vertexCount = 0;
public:
	BasicShader();
	~BasicShader();
	Q_DISABLE_COPY(BasicShader)
	void initialize(
		const char* vertexShaderSource,
		const char* fragmentShaderSource,
		QOpenGLBuffer::UsagePattern usagePattern,
		const std::vector<GLAttributeSpec>& attributeSpecs);
	void setUniformMatrix(const char* name, const glm::mat4& value);
	void setUniformVector(const char* name, const glm::vec4& value);
	void setMvpMatrix(const glm::mat4& newMvpMatrix);
	void bufferData(const void* data, std::size_t count, std::size_t size);
	void draw(GLenum drawMode);
	void teardown();
};

mercurial