src/gl/basicshaderprogram.h

Wed, 15 Jun 2022 12:33:16 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Wed, 15 Jun 2022 12:33:16 +0300
changeset 226
60d6b797a12e
parent 216
c7241f504117
child 250
2837b549e616
permissions
-rw-r--r--

remove old todo

#pragma once
#include "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 : protected QOpenGLFunctions
{
	bool isInitialized = false;
	QOpenGLBuffer buffer;
	QOpenGLShader vertexShader;
	QOpenGLShader fragmentShader;
	std::unique_ptr<gl::ShaderProgram> program = nullptr;
	QOpenGLVertexArrayObject vertexArrayObject;
	std::size_t 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