[core] Update RasterShader
Ref: https://github.com/mapbox/mapbox-gl-shaders/issues/1
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user