fix for retina screens
This commit is contained in:
@@ -232,10 +232,10 @@ void show_debug_image(std::string name, const char *data, size_t width, size_t h
|
||||
}
|
||||
|
||||
|
||||
void show_color_debug_image(std::string name, const char *data, size_t width, size_t height) {
|
||||
void show_color_debug_image(std::string name, const char *data, size_t logical_width, size_t logical_height, size_t width, size_t height) {
|
||||
static GLFWwindow *debug_window = nullptr;
|
||||
if (!debug_window) {
|
||||
debug_window = glfwCreateWindow(width, height, name.c_str(), nullptr, nullptr);
|
||||
debug_window = glfwCreateWindow(logical_width, logical_height, name.c_str(), nullptr, nullptr);
|
||||
if (!debug_window) {
|
||||
glfwTerminate();
|
||||
fprintf(stderr, "Failed to initialize window\n");
|
||||
@@ -245,14 +245,15 @@ void show_color_debug_image(std::string name, const char *data, size_t width, si
|
||||
|
||||
GLFWwindow *current_window = glfwGetCurrentContext();
|
||||
|
||||
glfwSetWindowSize(debug_window, width, height);
|
||||
glfwSetWindowSize(debug_window, logical_width, logical_height);
|
||||
glfwMakeContextCurrent(debug_window);
|
||||
|
||||
int fb_width, fb_height;
|
||||
glfwGetFramebufferSize(debug_window, &fb_width, &fb_height);
|
||||
float scale = (float)fb_width / (float)width;
|
||||
float x_scale = (float)fb_width / (float)width;
|
||||
float y_scale = (float)fb_height / (float)height;
|
||||
|
||||
glPixelZoom(scale, -scale);
|
||||
glPixelZoom(x_scale, -y_scale);
|
||||
glRasterPos2f(-1.0f, 1.0f);
|
||||
glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
|
||||
glfwSwapBuffers(debug_window);
|
||||
|
||||
@@ -36,7 +36,7 @@ void cancel_request_http(const std::shared_ptr<Request> &req);
|
||||
void show_debug_image(std::string name, const char *data, size_t width, size_t height);
|
||||
|
||||
// Shows an alpha image with the specified dimensions in a named window.
|
||||
void show_color_debug_image(std::string name, const char *data, size_t width, size_t height);
|
||||
void show_color_debug_image(std::string name, const char *data, size_t logical_width, size_t logical_height, size_t width, size_t height);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
void setColor(const std::array<float, 4>& color);
|
||||
void setDimension(const std::array<float, 2>& dimension);
|
||||
void setSize(float size);
|
||||
void setRatio(float ratio);
|
||||
|
||||
private:
|
||||
int32_t a_pos = -1;
|
||||
@@ -31,6 +32,9 @@ private:
|
||||
|
||||
float size = 0;
|
||||
int32_t u_size = -1;
|
||||
|
||||
float ratio = 0;
|
||||
int32_t u_ratio = -1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ Rect<SpriteAtlas::dimension> SpriteAtlas::getIcon(const int size, const std::str
|
||||
const int img_offset_y = (rect.y + buffer) * pixelRatio;
|
||||
|
||||
uint32_t *sprite_img = reinterpret_cast<uint32_t *>(data);
|
||||
const float blur = 1.5f / size;
|
||||
const float blur = 1.0f / size / pixelRatio;
|
||||
|
||||
const uint8_t r = 0x7F;
|
||||
const uint8_t g = 0x7F;
|
||||
@@ -220,7 +220,7 @@ void SpriteAtlas::bind(bool linear) {
|
||||
data // const GLvoid * data
|
||||
);
|
||||
|
||||
platform::show_color_debug_image("Sprite Atlas", data, width * pixelRatio, height * pixelRatio);
|
||||
platform::show_color_debug_image("Sprite Atlas", data, width, height, width * pixelRatio, height * pixelRatio);
|
||||
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ void Painter::renderIcon(IconBucket& bucket, const std::string& layer_name, cons
|
||||
iconShader->setMatrix(vtxMatrix);
|
||||
iconShader->setColor(color);
|
||||
iconShader->setImage(0);
|
||||
|
||||
iconShader->setRatio(map.getState().getPixelRatio());
|
||||
iconShader->setDimension({{
|
||||
spriteAtlas.getTextureWidth(),
|
||||
spriteAtlas.getTextureHeight(),
|
||||
|
||||
@@ -3,11 +3,12 @@ attribute vec2 a_tex;
|
||||
|
||||
uniform mat4 u_matrix;
|
||||
uniform float u_size;
|
||||
uniform float u_ratio;
|
||||
|
||||
varying vec2 v_tex;
|
||||
|
||||
void main() {
|
||||
gl_Position = u_matrix * vec4(a_pos, 0, 1);
|
||||
gl_PointSize = u_size;
|
||||
v_tex = a_tex;
|
||||
v_tex = a_tex * u_ratio;
|
||||
}
|
||||
|
||||
@@ -22,12 +22,14 @@ IconShader::IconShader()
|
||||
u_matrix = glGetUniformLocation(program, "u_matrix");
|
||||
u_color = glGetUniformLocation(program, "u_color");
|
||||
u_size = glGetUniformLocation(program, "u_size");
|
||||
u_ratio = glGetUniformLocation(program, "u_ratio");
|
||||
u_dimension = glGetUniformLocation(program, "u_dimension");
|
||||
|
||||
// fprintf(stderr, "IconShader:\n");
|
||||
// fprintf(stderr, " - u_matrix: %d\n", u_matrix);
|
||||
// fprintf(stderr, " - u_color: %d\n", u_color);
|
||||
// fprintf(stderr, " - u_size: %d\n", u_size);
|
||||
// fprintf(stderr, " - u_ratio: %d\n", u_ratio);
|
||||
// fprintf(stderr, " - u_dimension: %d\n", u_dimension);
|
||||
// fprintf(stderr, " - u_image: %d\n", u_image);
|
||||
}
|
||||
@@ -61,6 +63,13 @@ void IconShader::setSize(float new_size) {
|
||||
}
|
||||
}
|
||||
|
||||
void IconShader::setRatio(float new_ratio) {
|
||||
if (ratio != new_ratio) {
|
||||
glUniform1f(u_ratio, new_ratio);
|
||||
ratio = new_ratio;
|
||||
}
|
||||
}
|
||||
|
||||
void IconShader::setDimension(const std::array<float, 2>& new_dimension) {
|
||||
if (dimension != new_dimension) {
|
||||
glUniform2fv(u_dimension, 1, new_dimension.data());
|
||||
|
||||
@@ -11,7 +11,7 @@ const shader_source llmr::shaders[SHADER_COUNT] = {
|
||||
"#version 120\nuniform vec4 u_color;\nuniform float u_blur;\nvoid main ()\n{\n vec2 x_1;\n x_1 = (gl_PointCoord - 0.5);\n float tmpvar_2;\n tmpvar_2 = clamp (((\n sqrt(dot (x_1, x_1))\n - 0.5) / (\n (0.5 - u_blur)\n - 0.5)), 0.0, 1.0);\n gl_FragColor = (u_color * (tmpvar_2 * (tmpvar_2 * \n (3.0 - (2.0 * tmpvar_2))\n )));\n}\n\n",
|
||||
},
|
||||
{
|
||||
"#version 120\nattribute vec2 a_pos;\nattribute vec2 a_tex;\nuniform mat4 u_matrix;\nuniform float u_size;\nvarying vec2 v_tex;\nvoid main ()\n{\n vec4 tmpvar_1;\n tmpvar_1.zw = vec2(0.0, 1.0);\n tmpvar_1.xy = a_pos;\n gl_Position = (u_matrix * tmpvar_1);\n gl_PointSize = u_size;\n v_tex = a_tex;\n}\n\n",
|
||||
"#version 120\nattribute vec2 a_pos;\nattribute vec2 a_tex;\nuniform mat4 u_matrix;\nuniform float u_size;\nuniform float u_ratio;\nvarying vec2 v_tex;\nvoid main ()\n{\n vec4 tmpvar_1;\n tmpvar_1.zw = vec2(0.0, 1.0);\n tmpvar_1.xy = a_pos;\n gl_Position = (u_matrix * tmpvar_1);\n gl_PointSize = u_size;\n v_tex = (a_tex * u_ratio);\n}\n\n",
|
||||
"#version 120\nuniform sampler2D u_image;\nuniform vec2 u_dimension;\nuniform float u_size;\nvarying vec2 v_tex;\nvoid main ()\n{\n gl_FragColor = texture2D (u_image, ((v_tex + (\n (gl_PointCoord - 0.5)\n * u_size)) / u_dimension));\n}\n\n",
|
||||
},
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ const shader_source llmr::shaders[SHADER_COUNT] = {
|
||||
"precision highp float;\nuniform vec4 u_color;\nuniform float u_blur;\nvoid main ()\n{\n mediump vec2 x_1;\n x_1 = (gl_PointCoord - 0.5);\n mediump float tmpvar_2;\n tmpvar_2 = clamp (((\n sqrt(dot (x_1, x_1))\n - 0.5) / (\n (0.5 - u_blur)\n - 0.5)), 0.0, 1.0);\n gl_FragColor = (u_color * (tmpvar_2 * (tmpvar_2 * \n (3.0 - (2.0 * tmpvar_2))\n )));\n}\n\n",
|
||||
},
|
||||
{
|
||||
"precision highp float;\nattribute vec2 a_pos;\nattribute vec2 a_tex;\nuniform mat4 u_matrix;\nuniform float u_size;\nvarying vec2 v_tex;\nvoid main ()\n{\n vec4 tmpvar_1;\n tmpvar_1.zw = vec2(0.0, 1.0);\n tmpvar_1.xy = a_pos;\n gl_Position = (u_matrix * tmpvar_1);\n gl_PointSize = u_size;\n v_tex = a_tex;\n}\n\n",
|
||||
"precision highp float;\nattribute vec2 a_pos;\nattribute vec2 a_tex;\nuniform mat4 u_matrix;\nuniform float u_size;\nuniform float u_ratio;\nvarying vec2 v_tex;\nvoid main ()\n{\n vec4 tmpvar_1;\n tmpvar_1.zw = vec2(0.0, 1.0);\n tmpvar_1.xy = a_pos;\n gl_Position = (u_matrix * tmpvar_1);\n gl_PointSize = u_size;\n v_tex = (a_tex * u_ratio);\n}\n\n",
|
||||
"precision highp float;\nuniform sampler2D u_image;\nuniform vec2 u_dimension;\nuniform float u_size;\nvarying vec2 v_tex;\nvoid main ()\n{\n mediump vec2 tmpvar_1;\n tmpvar_1 = ((v_tex + (\n (gl_PointCoord - 0.5)\n * u_size)) / u_dimension);\n lowp vec4 tmpvar_2;\n tmpvar_2 = texture2D (u_image, tmpvar_1);\n gl_FragColor = tmpvar_2;\n}\n\n",
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user