add texture settings

This commit is contained in:
Konstantin Käfer
2014-02-19 18:14:42 +01:00
parent 9710fbef99
commit 7f5a674a91
5 changed files with 23 additions and 8 deletions

View File

@@ -11,6 +11,7 @@ public:
void bind(char *offset);
void setImage(int32_t image);
void setColor(const std::array<float, 4>& color);
void setPointTopLeft(const std::array<float, 2>& point_tl);
void setPointBottomRight(const std::array<float, 2>& point_br);
@@ -19,6 +20,9 @@ public:
private:
int32_t a_pos = -1;
int32_t image = -1;
int32_t u_image = -1;
std::array<float, 4> color = {};
int32_t u_color = -1;
@@ -31,7 +35,7 @@ private:
float size = 0;
int32_t u_size = -1;
};
}
#endif

View File

@@ -399,9 +399,11 @@ void Painter::renderPoint(PointBucket& bucket, const std::string& layer_name, co
ImagePosition imagePos = style.sprite->getPosition(sized_image, false);
// fprintf(stderr, "%f/%f => %f/%f\n", imagePos.tl.x, imagePos.tl.y, imagePos.br.x, imagePos.br.y);
useProgram(pointShader->program);
style.sprite->bind(transform.rotating || transform.scaling);
pointShader->setMatrix(matrix);
pointShader->setImage(0);
pointShader->setColor(color);
const float pointSize = properties.size * 1.4142135623730951;
#if defined(GL_ES_VERSION_2_0)
@@ -411,7 +413,7 @@ void Painter::renderPoint(PointBucket& bucket, const std::string& layer_name, co
#endif
pointShader->setPointTopLeft({{ imagePos.tl.x, imagePos.tl.y }});
pointShader->setPointBottomRight({{ imagePos.br.x, imagePos.br.y }});
style.sprite->bind(transform.rotating || transform.scaling);
bucket.drawPoints(*pointShader);
}

View File

@@ -37,6 +37,13 @@ void PointShader::bind(char *offset) {
glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset);
}
void PointShader::setImage(int32_t new_image) {
if (image != new_image) {
glUniform1i(u_image, new_image);
image = new_image;
}
}
void PointShader::setColor(const std::array<float, 4>& new_color) {
if (color != new_color) {
glUniform4fv(u_color, 1, new_color.data());

View File

@@ -10,11 +10,13 @@ uniform float inbounds;
uniform vec4 color;
void main() {
vec2 pos = (gl_PointCoord * 2.0 - 1.0) * root2 / 2.0 + 0.5;
// vec2 pos = (gl_PointCoord * 2.0 - 1.0) * root2 / 2.0 + 0.5;
float inbounds = step(0.0, pos.x) * step(0.0, pos.y) *
(1.0 - step(1.0, pos.x)) * (1.0 - step(1.0, pos.y));
// float inbounds = step(0.0, pos.x) * step(0.0, pos.y) *
// (1.0 - step(1.0, pos.x)) * (1.0 - step(1.0, pos.y));
// vec4 color = texture2D(u_image, mix(u_tl, u_br, pos)) * inbounds;
vec4 color = vec4(gl_PointCoord.s, gl_PointCoord.t, 0, 1);
vec4 color = texture2D(u_image, mix(u_tl, u_br, pos)) * inbounds;
gl_FragColor = color;
}

View File

@@ -26,6 +26,6 @@ const shader_source llmr::shaders[SHADER_COUNT] = {
},
{
"attribute vec2 a_pos;\n\nuniform mat4 u_matrix;\nuniform float u_size;\n\nvoid main() {\n gl_Position = u_matrix * vec4(a_pos, 0, 1);\n gl_PointSize = u_size;\n}\n",
"#define root2 1.4142135623730951\n\nuniform sampler2D u_image;\nuniform vec2 u_tl;\nuniform vec2 u_br;\nuniform vec4 u_color;\n\nuniform vec2 pos;\nuniform float inbounds;\nuniform vec4 color;\n\nvoid main() {\n vec2 pos = (gl_PointCoord * 2.0 - 1.0) * root2 / 2.0 + 0.5;\n\n float inbounds = step(0.0, pos.x) * step(0.0, pos.y) *\n (1.0 - step(1.0, pos.x)) * (1.0 - step(1.0, pos.y));\n\n vec4 color = texture2D(u_image, mix(u_tl, u_br, pos)) * inbounds;\n gl_FragColor = color;\n}\n",
"#define root2 1.4142135623730951\n\nuniform sampler2D u_image;\nuniform vec2 u_tl;\nuniform vec2 u_br;\nuniform vec4 u_color;\n\nuniform vec2 pos;\nuniform float inbounds;\nuniform vec4 color;\n\nvoid main() {\n // vec2 pos = (gl_PointCoord * 2.0 - 1.0) * root2 / 2.0 + 0.5;\n\n // float inbounds = step(0.0, pos.x) * step(0.0, pos.y) *\n // (1.0 - step(1.0, pos.x)) * (1.0 - step(1.0, pos.y));\n\n // vec4 color = texture2D(u_image, mix(u_tl, u_br, pos)) * inbounds;\n vec4 color = vec4(gl_PointCoord.s, gl_PointCoord.t, 0, 1);\n\n gl_FragColor = color;\n}\n",
}
};