diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-07-02 11:57:00 +0300 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-07-02 18:04:20 +0300 |
commit | aa1fa49af53d027ce9f030634b74b679b290e847 (patch) | |
tree | 0fd1260497cb86b72a3af8d2a25a65425fd97aaf | |
parent | 3bf85cc55d662c218e371a03040c4cd5c3cca771 (diff) | |
download | qtlocation-mapboxgl-aa1fa49af53d027ce9f030634b74b679b290e847.tar.gz |
[core] Update RasterShader
Ref: https://github.com/mapbox/mapbox-gl-shaders/issues/1
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_raster.cpp | 21 | ||||
-rw-r--r-- | src/mbgl/renderer/raster_bucket.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/renderer/raster_bucket.hpp | 5 | ||||
-rw-r--r-- | src/mbgl/shader/raster_shader.cpp | 7 | ||||
-rw-r--r-- | src/mbgl/shader/raster_shader.hpp | 10 | ||||
-rw-r--r-- | src/mbgl/shader/shader.cpp | 1 | ||||
-rw-r--r-- | src/mbgl/shader/shader.hpp | 13 |
8 files changed, 45 insertions, 22 deletions
diff --git a/package.json b/package.json index 9c067f8bbb..d959312fb6 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "csscolorparser": "^1.0.2", "ejs": "^2.4.1", "express": "^4.11.1", - "mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#59e998295d548f208ee3ec10cdd21ff2630e2079", + "mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#d3a10d1a46b99d3da264cf2d1903cbde6fea3185", "mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#194fc55b6a7dd54c1e2cf2dd9048fbb5e836716d", "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#2e5addbbd6b3eafaa2984bfd863fd28071f2e481", "node-gyp": "^3.3.1", diff --git a/src/mbgl/renderer/painter_raster.cpp b/src/mbgl/renderer/painter_raster.cpp index c137caf2f6..6f2352b0cd 100644 --- a/src/mbgl/renderer/painter_raster.cpp +++ b/src/mbgl/renderer/painter_raster.cpp @@ -18,12 +18,16 @@ void Painter::renderRaster(RasterBucket& bucket, const RasterPaintProperties& properties = layer.impl->paint; if (bucket.hasData()) { - const auto& shaderRaster = isOverdraw() ? rasterOverdrawShader : rasterShader; - auto& vaoRaster = isOverdraw() ? coveringRasterOverdrawArray : coveringRasterArray; + const bool overdraw = isOverdraw(); + const auto& shaderRaster = overdraw ? rasterOverdrawShader : rasterShader; + auto& vaoRaster = overdraw ? coveringRasterOverdrawArray : coveringRasterArray; + config.program = shaderRaster->getID(); shaderRaster->u_matrix = matrix; - shaderRaster->u_buffer = 0; - shaderRaster->u_opacity = properties.rasterOpacity; + shaderRaster->u_buffer_scale = 1.0f; + shaderRaster->u_opacity0 = properties.rasterOpacity; + shaderRaster->u_opacity1 = 1.0f - properties.rasterOpacity; + shaderRaster->u_brightness_low = properties.rasterBrightnessMin; shaderRaster->u_brightness_high = properties.rasterBrightnessMax; shaderRaster->u_saturation_factor = saturationFactor(properties.rasterSaturation); @@ -32,14 +36,17 @@ void Painter::renderRaster(RasterBucket& bucket, config.stencilTest = GL_FALSE; - shaderRaster->u_image = 0; - config.activeTexture = GL_TEXTURE0; + shaderRaster->u_image0 = 0; // GL_TEXTURE0 + shaderRaster->u_image1 = 1; // GL_TEXTURE1 + shaderRaster->u_tl_parent = {{ 0.0f, 0.0f }}; + shaderRaster->u_scale_parent = 1.0f; config.depthFunc.reset(); config.depthTest = GL_TRUE; config.depthMask = GL_FALSE; setDepthSublayer(0); - bucket.drawRaster(*shaderRaster, tileStencilBuffer, vaoRaster, store); + + bucket.drawRaster(*shaderRaster, rasterBoundsBuffer, vaoRaster, config, store); } } diff --git a/src/mbgl/renderer/raster_bucket.cpp b/src/mbgl/renderer/raster_bucket.cpp index 46c034f4d9..2020860396 100644 --- a/src/mbgl/renderer/raster_bucket.cpp +++ b/src/mbgl/renderer/raster_bucket.cpp @@ -26,12 +26,16 @@ void RasterBucket::setImage(PremultipliedImage image) { } void RasterBucket::drawRaster(RasterShader& shader, - StaticVertexBuffer& vertices, + StaticRasterVertexBuffer& vertices, VertexArrayObject& array, + gl::Config& config, gl::ObjectStore& store) { + config.activeTexture = GL_TEXTURE0; + raster.bind(true, store); + config.activeTexture = GL_TEXTURE1; raster.bind(true, store); array.bind(shader, vertices, BUFFER_OFFSET_0, store); - MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertices.index())); + MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)vertices.index())); } bool RasterBucket::hasData() const { diff --git a/src/mbgl/renderer/raster_bucket.hpp b/src/mbgl/renderer/raster_bucket.hpp index 5a152bbfa4..35b1bc2b51 100644 --- a/src/mbgl/renderer/raster_bucket.hpp +++ b/src/mbgl/renderer/raster_bucket.hpp @@ -2,11 +2,12 @@ #include <mbgl/renderer/bucket.hpp> #include <mbgl/util/raster.hpp> +#include <mbgl/gl/gl_config.hpp> namespace mbgl { class RasterShader; -class StaticVertexBuffer; +class StaticRasterVertexBuffer; class VertexArrayObject; class RasterBucket : public Bucket { @@ -18,7 +19,7 @@ public: void setImage(PremultipliedImage); - void drawRaster(RasterShader&, StaticVertexBuffer&, VertexArrayObject&, gl::ObjectStore&); + void drawRaster(RasterShader&, StaticRasterVertexBuffer&, VertexArrayObject&, gl::Config&, gl::ObjectStore&); Raster raster; }; diff --git a/src/mbgl/shader/raster_shader.cpp b/src/mbgl/shader/raster_shader.cpp index 17953ab903..eb431cd5db 100644 --- a/src/mbgl/shader/raster_shader.cpp +++ b/src/mbgl/shader/raster_shader.cpp @@ -13,8 +13,13 @@ RasterShader::RasterShader(gl::ObjectStore& store, bool overdraw) } void RasterShader::bind(GLbyte* offset) { + const GLint stride = 8; + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset)); + + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_texture_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_texture_pos, 2, GL_SHORT, false, stride, offset + 4)); } } // namespace mbgl diff --git a/src/mbgl/shader/raster_shader.hpp b/src/mbgl/shader/raster_shader.hpp index 9c658c8d54..677fe927ab 100644 --- a/src/mbgl/shader/raster_shader.hpp +++ b/src/mbgl/shader/raster_shader.hpp @@ -12,14 +12,18 @@ public: void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform<GLint> u_image = {"u_image", *this}; - Uniform<GLfloat> u_opacity = {"u_opacity", *this}; - Uniform<GLfloat> u_buffer = {"u_buffer", *this}; + Uniform<GLint> u_image0 = {"u_image0", *this}; + Uniform<GLint> u_image1 = {"u_image1", *this}; + Uniform<GLfloat> u_opacity0 = {"u_opacity0", *this}; + Uniform<GLfloat> u_opacity1 = {"u_opacity1", *this}; + Uniform<GLfloat> u_buffer_scale = {"u_buffer_scale", *this}; Uniform<GLfloat> u_brightness_low = {"u_brightness_low", *this}; Uniform<GLfloat> u_brightness_high = {"u_brightness_high", *this}; Uniform<GLfloat> u_saturation_factor = {"u_saturation_factor", *this}; Uniform<GLfloat> u_contrast_factor = {"u_contrast_factor", *this}; Uniform<std::array<GLfloat, 3>> u_spin_weights = {"u_spin_weights", *this}; + Uniform<std::array<GLfloat, 2>> u_tl_parent = {"u_tl_parent", *this}; + Uniform<GLfloat> u_scale_parent = {"u_scale_parent", *this}; }; } // namespace mbgl diff --git a/src/mbgl/shader/shader.cpp b/src/mbgl/shader/shader.cpp index c9a6b89ade..464eba1ae2 100644 --- a/src/mbgl/shader/shader.cpp +++ b/src/mbgl/shader/shader.cpp @@ -50,6 +50,7 @@ Shader::Shader(const char* name_, const char* vertexSource, const char* fragment MBGL_CHECK_ERROR(glBindAttribLocation(program.get(), a_data, "a_data")); MBGL_CHECK_ERROR(glBindAttribLocation(program.get(), a_data1, "a_data1")); MBGL_CHECK_ERROR(glBindAttribLocation(program.get(), a_data2, "a_data2")); + MBGL_CHECK_ERROR(glBindAttribLocation(program.get(), a_texture_pos, "a_texture_pos")); // Link program GLint status; diff --git a/src/mbgl/shader/shader.hpp b/src/mbgl/shader/shader.hpp index 81ee024934..829abad3a0 100644 --- a/src/mbgl/shader/shader.hpp +++ b/src/mbgl/shader/shader.hpp @@ -21,12 +21,13 @@ public: protected: Shader(const char* name_, const char* vertex, const char* fragment, gl::ObjectStore&, bool overdraw = false); - static constexpr GLint a_pos = 0; - static constexpr GLint a_extrude = 1; - static constexpr GLint a_offset = 2; - static constexpr GLint a_data = 3; - static constexpr GLint a_data1 = 4; - static constexpr GLint a_data2 = 5; + static constexpr GLint a_pos = 0; + static constexpr GLint a_extrude = 1; + static constexpr GLint a_offset = 2; + static constexpr GLint a_data = 3; + static constexpr GLint a_data1 = 4; + static constexpr GLint a_data2 = 5; + static constexpr GLint a_texture_pos = 6; private: bool compileShader(gl::UniqueShader&, const GLchar *source); |