src/gl/vertexprogram.cpp

changeset 119
24275a4064f4
parent 118
8e1c9f18ae15
child 120
8c9fff699241
--- a/src/gl/vertexprogram.cpp	Tue Jul 27 16:29:00 2021 +0300
+++ b/src/gl/vertexprogram.cpp	Wed Jul 28 08:23:09 2021 +0300
@@ -3,7 +3,8 @@
 
 static const char vertexShaderSource[] = R"(
 #version 330 core
-
+const int FRAGSTYLE_Normal = 0;
+const int FRAGSTYLE_Id = 1;
 layout (location = 0) in vec3 in_position;
 layout (location = 1) in vec3 in_color;
 uniform mat4 view;
@@ -30,8 +31,18 @@
 }
 )";
 
-static constexpr int VERTICES_PER_OBJECT = 16;
+static constexpr glm::vec3 o = {0, 0, 0};
+static constexpr glm::vec3 c1 = {1, -1, 1};
+static constexpr glm::vec3 c2 = {1, -1, -1};
+static constexpr glm::vec3 c3 = {-1, -1, -1};
+static constexpr glm::vec3 c4 = {-1, -1, 1};
 
+static constexpr glm::vec3 markerGeometry[] = {
+	o, c1, c2,
+	o, c2, c3,
+	o, c3, c4,
+	o, c4, c1,
+};
 
 VertexProgram::VertexProgram(QObject *parent) :
 	AbstractBasicShaderProgram{parent}
@@ -76,7 +87,7 @@
 
 GLenum VertexProgram::drawMode() const
 {
-	return GL_LINES;
+	return GL_TRIANGLES;
 }
 
 QOpenGLBuffer::UsagePattern VertexProgram::usagePattern() const
@@ -84,6 +95,11 @@
 	return QOpenGLBuffer::DynamicDraw;
 }
 
+void VertexProgram::setFragmentStyle(const FragmentStyle newFragmentStyle)
+{
+	this->fragmentStyle = newFragmentStyle;
+}
+
 void VertexProgram::build(const Document *document)
 {
 	constexpr float size = 1;
@@ -91,23 +107,11 @@
 	this->data.clear();
 	document->applyToVertices([&](const glm::vec3& vertex, const std::set<ldraw::id_t>&)
 	{
-		reserveMore(this->data, VERTICES_PER_OBJECT);
-		this->data.push_back({vertex, color});
-		this->data.push_back({vertex + glm::vec3{size, -size, size}, color});
-		this->data.push_back({vertex, color});
-		this->data.push_back({vertex + glm::vec3{size, -size, -size}, color});
-		this->data.push_back({vertex, color});
-		this->data.push_back({vertex + glm::vec3{-size, -size, -size}, color});
-		this->data.push_back({vertex, color});
-		this->data.push_back({vertex + glm::vec3{-size, -size, size}, color});
-		this->data.push_back({vertex + glm::vec3{size, -size, size}, color});
-		this->data.push_back({vertex + glm::vec3{size, -size, -size}, color});
-		this->data.push_back({vertex + glm::vec3{size, -size, -size}, color});
-		this->data.push_back({vertex + glm::vec3{-size, -size, -size}, color});
-		this->data.push_back({vertex + glm::vec3{-size, -size, -size}, color});
-		this->data.push_back({vertex + glm::vec3{-size, -size, size}, color});
-		this->data.push_back({vertex + glm::vec3{-size, -size, size}, color});
-		this->data.push_back({vertex + glm::vec3{size, -size, size}, color});
+		reserveMore(this->data, ::countof(::markerGeometry));
+		for (const glm::vec3& point : ::markerGeometry)
+		{
+			this->data.push_back({vertex + point * size, color});
+		}
 	});
 	this->buffer.bind();
 	this->buffer.allocate(this->vertexData(), this->vertexCount() * this->vertexSize());

mercurial