summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-01-29 15:09:00 +0100
committerKonstantin Käfer <mail@kkaefer.com>2014-01-29 15:09:00 +0100
commit1233537713bdba77c3879135d7a1008fc97b5581 (patch)
tree03a31ef6c42639f240c222336bf9ddc0bb7c7fcd
parent29f0214eea44042193340a04be3444edf86a384b (diff)
downloadqtlocation-mapboxgl-1233537713bdba77c3879135d7a1008fc97b5581.tar.gz
float[16] => std::array<float, 16>
-rw-r--r--include/llmr/map/transform.hpp3
-rw-r--r--include/llmr/renderer/painter.hpp7
-rw-r--r--include/llmr/util/mat4.hpp23
-rw-r--r--src/map/transform.cpp16
-rw-r--r--src/renderer/painter.cpp38
-rw-r--r--src/util/mat4.cpp16
6 files changed, 55 insertions, 48 deletions
diff --git a/include/llmr/map/transform.hpp b/include/llmr/map/transform.hpp
index 43a1e655e3..39b533c6b8 100644
--- a/include/llmr/map/transform.hpp
+++ b/include/llmr/map/transform.hpp
@@ -3,6 +3,7 @@
#include <llmr/util/vec.hpp>
+#include <llmr/util/mat4.hpp>
#include <llmr/util/animation.hpp>
#include <cmath>
@@ -39,7 +40,7 @@ public:
void setLonLat(double lon, double lat);
// Getters
- void matrixFor(float matrix[16], const vec3<int32_t>& id) const;
+ void matrixFor(mat4& matrix, const vec3<int32_t>& id) const;
float getZoom() const;
int32_t getIntegerZoom() const;
double getScale() const;
diff --git a/include/llmr/renderer/painter.hpp b/include/llmr/renderer/painter.hpp
index e9b475f73b..44cd3da4d6 100644
--- a/include/llmr/renderer/painter.hpp
+++ b/include/llmr/renderer/painter.hpp
@@ -7,6 +7,7 @@
#include "shader-line.hpp"
#include "../map/tile.hpp"
+#include "../util/mat4.hpp"
namespace llmr {
@@ -57,9 +58,9 @@ private:
Settings& settings;
Style& style;
- float nativeMatrix[16];
- float matrix[16];
- float exMatrix[16];
+ mat4 nativeMatrix;
+ mat4 matrix;
+ mat4 exMatrix;
std::shared_ptr<Shader> currentShader;
std::shared_ptr<FillShader> fillShader;
diff --git a/include/llmr/util/mat4.hpp b/include/llmr/util/mat4.hpp
index 05c1b7b161..a5dc83f7d1 100644
--- a/include/llmr/util/mat4.hpp
+++ b/include/llmr/util/mat4.hpp
@@ -23,16 +23,21 @@
#ifndef LLMR_UTIL_MAT4
#define LLMR_UTIL_MAT4
+#include <array>
+
namespace llmr {
-namespace mat4 {
-
-void identity(float out[16]);
-void ortho(float out[16], float left, float right, float bottom, float top, float near, float far);
-void copy(float out[16], float a[16]);
-void translate(float out[16], float a[16], float x, float y, float z);
-void rotate_z(float out[16], float a[16], float rad);
-void scale(float out[16], float a[16], float x, float y, float z);
-void multiply(float out[16], float a[16], float b[16]);
+
+typedef std::array<float, 16> mat4;
+
+namespace matrix {
+
+void identity(mat4& out);
+void ortho(mat4& out, float left, float right, float bottom, float top, float near, float far);
+void copy(mat4& out, const mat4& a);
+void translate(mat4& out, const mat4& a, float x, float y, float z);
+void rotate_z(mat4& out, const mat4& a, float rad);
+void scale(mat4& out, const mat4& a, float x, float y, float z);
+void multiply(mat4& out, const mat4& a, const mat4& b);
}
}
diff --git a/src/map/transform.cpp b/src/map/transform.cpp
index 023e7c302d..98fb0ba206 100644
--- a/src/map/transform.cpp
+++ b/src/map/transform.cpp
@@ -135,23 +135,23 @@ double Transform::pixel_y() const {
return center + y;
}
-void Transform::matrixFor(float matrix[16], const vec3<int32_t>& id) const {
+void Transform::matrixFor(mat4& matrix, const vec3<int32_t>& id) const {
const double tile_scale = pow(2, id.z);
const double tile_size = scale * size / tile_scale;
- mat4::identity(matrix);
+ matrix::identity(matrix);
- mat4::translate(matrix, matrix, 0.5f * (float)width, 0.5f * (float)height, 0);
- mat4::rotate_z(matrix, matrix, angle);
- mat4::translate(matrix, matrix, -0.5f * (float)width, -0.5f * (float)height, 0);
+ matrix::translate(matrix, matrix, 0.5f * (float)width, 0.5f * (float)height, 0);
+ matrix::rotate_z(matrix, matrix, angle);
+ matrix::translate(matrix, matrix, -0.5f * (float)width, -0.5f * (float)height, 0);
- mat4::translate(matrix, matrix, pixel_x() + id.x * tile_size, pixel_y() + id.y * tile_size, 0);
+ matrix::translate(matrix, matrix, pixel_x() + id.x * tile_size, pixel_y() + id.y * tile_size, 0);
// TODO: Get rid of the 8 (scaling from 4096 to 512 px tile size);
- mat4::scale(matrix, matrix, scale / tile_scale / 8, scale / tile_scale / 8, 1);
+ matrix::scale(matrix, matrix, scale / tile_scale / 8, scale / tile_scale / 8, 1);
// Clipping plane
- mat4::translate(matrix, matrix, 0, 0, -1);
+ matrix::translate(matrix, matrix, 0, 0, -1);
}
float Transform::getZoom() const {
diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp
index f3e265c69b..6c35db8c32 100644
--- a/src/renderer/painter.cpp
+++ b/src/renderer/painter.cpp
@@ -107,28 +107,28 @@ void Painter::teardown() {
void Painter::changeMatrix(const Tile::Ptr& tile) {
// Initialize projection matrix
- float projMatrix[16];
- mat4::ortho(projMatrix, 0, transform.width, transform.height, 0, 1, 10);
+ mat4 projMatrix;
+ matrix::ortho(projMatrix, 0, transform.width, transform.height, 0, 1, 10);
// The position matrix.
transform.matrixFor(matrix, tile->id);
- mat4::multiply(matrix, projMatrix, matrix);
+ matrix::multiply(matrix, projMatrix, matrix);
// The extrusion matrix.
- mat4::identity(exMatrix);
- mat4::multiply(exMatrix, projMatrix, exMatrix);
- mat4::rotate_z(exMatrix, exMatrix, transform.getAngle());
+ matrix::identity(exMatrix);
+ matrix::multiply(exMatrix, projMatrix, exMatrix);
+ matrix::rotate_z(exMatrix, exMatrix, transform.getAngle());
// The native matrix is a 1:1 matrix that paints the coordinates at the
// same screen position as the vertex specifies.
- mat4::identity(nativeMatrix);
- mat4::translate(nativeMatrix, nativeMatrix, 0, 0, -1);
- mat4::multiply(nativeMatrix, projMatrix, nativeMatrix);
+ matrix::identity(nativeMatrix);
+ matrix::translate(nativeMatrix, nativeMatrix, 0, 0, -1);
+ matrix::multiply(nativeMatrix, projMatrix, nativeMatrix);
}
void Painter::drawClippingMask() {
switchShader(plainShader);
- glUniformMatrix4fv(plainShader->u_matrix, 1, GL_FALSE, matrix);
+ glUniformMatrix4fv(plainShader->u_matrix, 1, GL_FALSE, matrix.data());
glColorMask(false, false, false, false);
@@ -251,7 +251,7 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name) {
// Draw the actual triangle fan into the stencil buffer.
switchShader(fillShader);
- glUniformMatrix4fv(fillShader->u_matrix, 1, GL_FALSE, matrix);
+ glUniformMatrix4fv(fillShader->u_matrix, 1, GL_FALSE, matrix.data());
// Draw all groups
bucket.drawElements(fillShader->a_pos);
@@ -269,7 +269,7 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name) {
// below, we have to draw the outline first (!)
if (properties.antialias) {
switchShader(outlineShader);
- glUniformMatrix4fv(outlineShader->u_matrix, 1, GL_FALSE, matrix);
+ glUniformMatrix4fv(outlineShader->u_matrix, 1, GL_FALSE, matrix.data());
glLineWidth(2);
if (properties.stroke_color != properties.fill_color) {
@@ -321,7 +321,7 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name) {
} else {
// Draw filling rectangle.
switchShader(fillShader);
- glUniformMatrix4fv(fillShader->u_matrix, 1, GL_FALSE, matrix);
+ glUniformMatrix4fv(fillShader->u_matrix, 1, GL_FALSE, matrix.data());
glUniform4fv(fillShader->u_color, 1, fill_color.data());
}
@@ -374,8 +374,8 @@ void Painter::renderLine(LineBucket& bucket, const std::string& layer_name) {
} else {
switchShader(lineShader);
- glUniformMatrix4fv(lineShader->u_matrix, 1, GL_FALSE, matrix);
- glUniformMatrix4fv(lineShader->u_exmatrix, 1, GL_FALSE, exMatrix);
+ glUniformMatrix4fv(lineShader->u_matrix, 1, GL_FALSE, matrix.data());
+ glUniformMatrix4fv(lineShader->u_exmatrix, 1, GL_FALSE, exMatrix.data());
// glUniform2fv(painter.lineShader.u_dasharray, properties.dasharray || [1, -1]);
glUniform2f(lineShader->u_dasharray, 1, -1);
}
@@ -421,7 +421,7 @@ void Painter::renderDebug(const Tile::Ptr& tile) {
// draw tile outline
switchShader(plainShader);
- glUniformMatrix4fv(plainShader->u_matrix, 1, GL_FALSE, matrix);
+ glUniformMatrix4fv(plainShader->u_matrix, 1, GL_FALSE, matrix.data());
glBindBuffer(GL_ARRAY_BUFFER, tile_border_buffer);
glVertexAttribPointer(plainShader->a_pos, 2, GL_SHORT, false, 0, BUFFER_OFFSET(0));
glUniform4f(plainShader->u_color, 1.0f, 1.0f, 1.0f, 1.0f);
@@ -430,7 +430,7 @@ void Painter::renderDebug(const Tile::Ptr& tile) {
// draw debug info
switchShader(plainShader);
- glUniformMatrix4fv(plainShader->u_matrix, 1, GL_FALSE, matrix);
+ glUniformMatrix4fv(plainShader->u_matrix, 1, GL_FALSE, matrix.data());
tile->debugFontBuffer->bind();
glVertexAttribPointer(plainShader->a_pos, 2, GL_SHORT, GL_FALSE, 0, BUFFER_OFFSET(0));
glUniform4f(plainShader->u_color, 1.0f, 1.0f, 1.0f, 1.0f);
@@ -448,7 +448,7 @@ void Painter::renderMatte() {
glDisable(GL_STENCIL_TEST);
switchShader(fillShader);
- glUniformMatrix4fv(fillShader->u_matrix, 1, GL_FALSE, nativeMatrix);
+ glUniformMatrix4fv(fillShader->u_matrix, 1, GL_FALSE, nativeMatrix.data());
Color white = {{ 1, 1, 1, 1 }};
@@ -463,7 +463,7 @@ void Painter::renderMatte() {
void Painter::renderBackground() {
switchShader(fillShader);
- glUniformMatrix4fv(fillShader->u_matrix, 1, GL_FALSE, matrix);
+ glUniformMatrix4fv(fillShader->u_matrix, 1, GL_FALSE, matrix.data());
Color white = {{ 1, 1, 1, 1 }};
diff --git a/src/util/mat4.cpp b/src/util/mat4.cpp
index 861ad5c035..44bd3edd7c 100644
--- a/src/util/mat4.cpp
+++ b/src/util/mat4.cpp
@@ -26,7 +26,7 @@
using namespace llmr;
-void mat4::identity(float out[16]) {
+void matrix::identity(mat4& out) {
out[0] = 1.0f;
out[1] = 0.0f;
out[2] = 0.0f;
@@ -45,7 +45,7 @@ void mat4::identity(float out[16]) {
out[15] = 1.0f;
}
-void mat4::ortho(float out[16], float left, float right, float bottom, float top, float near, float far) {
+void matrix::ortho(mat4& out, float left, float right, float bottom, float top, float near, float far) {
float lr = 1.0f / (left - right),
bt = 1.0f / (bottom - top),
nf = 1.0f / (near - far);
@@ -67,7 +67,7 @@ void mat4::ortho(float out[16], float left, float right, float bottom, float top
out[15] = 1.0f;
}
-void mat4::copy(float out[16], float a[16]) {
+void matrix::copy(mat4& out, const mat4& a) {
out[0] = a[0];
out[1] = a[1];
out[2] = a[2];
@@ -86,7 +86,7 @@ void mat4::copy(float out[16], float a[16]) {
out[15] = a[15];
}
-void mat4::translate(float out[16], float a[16], float x, float y, float z) {
+void matrix::translate(mat4& out, const mat4& a, float x, float y, float z) {
float a00, a01, a02, a03,
a10, a11, a12, a13,
a20, a21, a22, a23;
@@ -112,7 +112,7 @@ void mat4::translate(float out[16], float a[16], float x, float y, float z) {
}
}
-void mat4::rotate_z(float out[16], float a[16], float rad) {
+void matrix::rotate_z(mat4& out, const mat4& a, float rad) {
float s = sin(rad),
c = cos(rad),
a00 = a[0],
@@ -146,7 +146,7 @@ void mat4::rotate_z(float out[16], float a[16], float rad) {
out[7] = a13 * c - a03 * s;
}
-void mat4::scale(float out[16], float a[16], float x, float y, float z) {
+void matrix::scale(mat4& out, const mat4& a, float x, float y, float z) {
out[0] = a[0] * x;
out[1] = a[1] * x;
out[2] = a[2] * x;
@@ -165,14 +165,14 @@ void mat4::scale(float out[16], float a[16], float x, float y, float z) {
out[15] = a[15];
}
-void mat4::multiply(float out[16], float a[16], float b[16]) {
+void matrix::multiply(mat4& out, const mat4& a, const mat4& b) {
float a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
// Cache only the current line of the second matrix
- float b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
+ float b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;