src/gl/basicshaderprogram.h

Thu, 15 Jun 2023 16:18:03 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Thu, 15 Jun 2023 16:18:03 +0300
changeset 383
530d23cd4e97
parent 378
01537fbe096e
permissions
-rw-r--r--

Refactor, make selecting elements from the model select the corresponding line from the editor as well

#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