From 5ae098daff2097ffe3514a1ed06c8b007c4b02c8 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Mon, 3 Oct 2022 01:02:05 -0500 Subject: [PATCH] Geo line requires two projection matrices --- scwx-qt/gl/geo_line.vert | 6 ++++-- scwx-qt/source/scwx/qt/gl/draw/geo_line.cpp | 13 +++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/scwx-qt/gl/geo_line.vert b/scwx-qt/gl/geo_line.vert index e232df95..4fea6910 100644 --- a/scwx-qt/gl/geo_line.vert +++ b/scwx-qt/gl/geo_line.vert @@ -12,6 +12,7 @@ layout (location = 2) in vec2 aTexCoord; layout (location = 3) in vec4 aModulate; uniform mat4 uMVPMatrix; +uniform mat4 uMapMatrix; uniform vec2 uMapScreenCoord; flat out vec2 texCoord; @@ -32,8 +33,9 @@ void main() texCoord = aTexCoord; modulate = aModulate; - vec2 p = latLngToScreenCoordinate(aLatLong) + aXYOffset - uMapScreenCoord; + vec2 p = latLngToScreenCoordinate(aLatLong) - uMapScreenCoord; // Transform the position to screen coordinates - gl_Position = uMVPMatrix * vec4(p, 0.0f, 1.0f); + gl_Position = uMapMatrix * vec4(p, 0.0f, 1.0f) - + uMVPMatrix * vec4(aXYOffset, 0.0f, 0.0f); } diff --git a/scwx-qt/source/scwx/qt/gl/draw/geo_line.cpp b/scwx-qt/source/scwx/qt/gl/draw/geo_line.cpp index 2ab6047f..56f8c16b 100644 --- a/scwx-qt/source/scwx/qt/gl/draw/geo_line.cpp +++ b/scwx-qt/source/scwx/qt/gl/draw/geo_line.cpp @@ -36,6 +36,7 @@ public: modulateColor_ {std::nullopt}, shaderProgram_ {nullptr}, uMVPMatrixLocation_(GL_INVALID_INDEX), + uMapMatrixLocation_(GL_INVALID_INDEX), uMapScreenCoordLocation_(GL_INVALID_INDEX), vao_ {GL_INVALID_INDEX}, vbo_ {GL_INVALID_INDEX} @@ -58,6 +59,7 @@ public: std::shared_ptr shaderProgram_; GLint uMVPMatrixLocation_; + GLint uMapMatrixLocation_; GLint uMapScreenCoordLocation_; GLuint vao_; @@ -66,7 +68,6 @@ public: void Update(); }; -// TODO: OpenGL context with shaders GeoLine::GeoLine(std::shared_ptr context) : DrawItem(context->gl()), p(std::make_unique(context)) { @@ -90,6 +91,13 @@ void GeoLine::Initialize() logger_->warn("Could not find uMVPMatrix"); } + p->uMapMatrixLocation_ = + gl.glGetUniformLocation(p->shaderProgram_->id(), "uMapMatrix"); + if (p->uMapMatrixLocation_ == -1) + { + logger_->warn("Could not find uMapMatrix"); + } + p->uMapScreenCoordLocation_ = gl.glGetUniformLocation(p->shaderProgram_->id(), "uMapScreenCoord"); if (p->uMapScreenCoordLocation_ == -1) @@ -155,8 +163,9 @@ void GeoLine::Render(const QMapbox::CustomLayerRenderParameters& params) p->Update(); p->shaderProgram_->Use(); + UseDefaultProjection(params, p->uMVPMatrixLocation_); UseMapProjection( - params, p->uMVPMatrixLocation_, p->uMapScreenCoordLocation_); + params, p->uMapMatrixLocation_, p->uMapScreenCoordLocation_); // Draw line gl.glDrawArrays(GL_TRIANGLES, 0, 6);