Geo line requires two projection matrices

This commit is contained in:
Dan Paulat 2022-10-03 01:02:05 -05:00
parent 4aad9fd3d4
commit 5ae098daff
2 changed files with 15 additions and 4 deletions

View file

@ -12,6 +12,7 @@ layout (location = 2) in vec2 aTexCoord;
layout (location = 3) in vec4 aModulate; layout (location = 3) in vec4 aModulate;
uniform mat4 uMVPMatrix; uniform mat4 uMVPMatrix;
uniform mat4 uMapMatrix;
uniform vec2 uMapScreenCoord; uniform vec2 uMapScreenCoord;
flat out vec2 texCoord; flat out vec2 texCoord;
@ -32,8 +33,9 @@ void main()
texCoord = aTexCoord; texCoord = aTexCoord;
modulate = aModulate; modulate = aModulate;
vec2 p = latLngToScreenCoordinate(aLatLong) + aXYOffset - uMapScreenCoord; vec2 p = latLngToScreenCoordinate(aLatLong) - uMapScreenCoord;
// Transform the position to screen coordinates // 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);
} }

View file

@ -36,6 +36,7 @@ public:
modulateColor_ {std::nullopt}, modulateColor_ {std::nullopt},
shaderProgram_ {nullptr}, shaderProgram_ {nullptr},
uMVPMatrixLocation_(GL_INVALID_INDEX), uMVPMatrixLocation_(GL_INVALID_INDEX),
uMapMatrixLocation_(GL_INVALID_INDEX),
uMapScreenCoordLocation_(GL_INVALID_INDEX), uMapScreenCoordLocation_(GL_INVALID_INDEX),
vao_ {GL_INVALID_INDEX}, vao_ {GL_INVALID_INDEX},
vbo_ {GL_INVALID_INDEX} vbo_ {GL_INVALID_INDEX}
@ -58,6 +59,7 @@ public:
std::shared_ptr<ShaderProgram> shaderProgram_; std::shared_ptr<ShaderProgram> shaderProgram_;
GLint uMVPMatrixLocation_; GLint uMVPMatrixLocation_;
GLint uMapMatrixLocation_;
GLint uMapScreenCoordLocation_; GLint uMapScreenCoordLocation_;
GLuint vao_; GLuint vao_;
@ -66,7 +68,6 @@ public:
void Update(); void Update();
}; };
// TODO: OpenGL context with shaders
GeoLine::GeoLine(std::shared_ptr<GlContext> context) : GeoLine::GeoLine(std::shared_ptr<GlContext> context) :
DrawItem(context->gl()), p(std::make_unique<Impl>(context)) DrawItem(context->gl()), p(std::make_unique<Impl>(context))
{ {
@ -90,6 +91,13 @@ void GeoLine::Initialize()
logger_->warn("Could not find uMVPMatrix"); 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_ = p->uMapScreenCoordLocation_ =
gl.glGetUniformLocation(p->shaderProgram_->id(), "uMapScreenCoord"); gl.glGetUniformLocation(p->shaderProgram_->id(), "uMapScreenCoord");
if (p->uMapScreenCoordLocation_ == -1) if (p->uMapScreenCoordLocation_ == -1)
@ -155,8 +163,9 @@ void GeoLine::Render(const QMapbox::CustomLayerRenderParameters& params)
p->Update(); p->Update();
p->shaderProgram_->Use(); p->shaderProgram_->Use();
UseDefaultProjection(params, p->uMVPMatrixLocation_);
UseMapProjection( UseMapProjection(
params, p->uMVPMatrixLocation_, p->uMapScreenCoordLocation_); params, p->uMapMatrixLocation_, p->uMapScreenCoordLocation_);
// Draw line // Draw line
gl.glDrawArrays(GL_TRIANGLES, 0, 6); gl.glDrawArrays(GL_TRIANGLES, 0, 6);