src/gl/basicshaderprogram.h

Sat, 10 Jun 2023 17:26:32 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sat, 10 Jun 2023 17:26:32 +0300
changeset 382
94d5587bb0c4
parent 378
01537fbe096e
permissions
-rw-r--r--

use a parameter to avoid temporarily changing member variables

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

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

namespace gl
{
	struct basic_shader;
	void initialize_basic_shader(
		gl::basic_shader* shader,
		const char* vertexShaderSource,
		const char* fragmentShaderSource,
		QOpenGLBuffer::UsagePattern usagePattern,
		const std::vector<GLAttributeSpec>& attributeSpecs);
	void set_shader_matrix_uniform(
		gl::basic_shader* shader,
		const char* name,
		const glm::mat4& value);
	void set_shader_vector_uniform(
		gl::basic_shader* shader,
		const char* name,
		const glm::vec4& value);
	void buffer_shader_data(
		gl::basic_shader* shader,
		const void* data,
		std::size_t count,
		std::size_t size);
	void draw_shader(
		gl::basic_shader* shader,
		GLenum drawMode);
}

//! @brief A collection of a single VAO with a single VBO,
//! a vertex shader and a fragment shader.
struct gl::basic_shader
{
	QOpenGLBuffer buffer{QOpenGLBuffer::VertexBuffer};
	QOpenGLShader vertexShader{QOpenGLShader::Vertex};
	QOpenGLShader fragmentShader{QOpenGLShader::Fragment};
	std::unique_ptr<gl::ShaderProgram> program = nullptr;
	QOpenGLVertexArrayObject vertexArrayObject;
	int vertexCount = 0;
};

mercurial