Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Update RasterShader
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Jun 19, 2016
1 parent 5a79ee4 commit 272da62
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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#27fdfc994df4704bfe55144f9b5e25ae9e5afa4d",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#194fc55b6a7dd54c1e2cf2dd9048fbb5e836716d",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#3a6baea2f364410e6d0873b71babfe0484870a72",
"node-gyp": "^3.3.1",
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/geometry/static_vertex_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ StaticVertexBuffer::StaticVertexBuffer(std::initializer_list<std::pair<VertexTyp
}
}

StaticRasterVertexBuffer::StaticRasterVertexBuffer(std::initializer_list<std::tuple<VertexType, VertexType, VertexType, VertexType>> init) {
StaticRasterVertexBuffer::StaticRasterVertexBuffer(std::initializer_list<std::array<VertexType, 4>> init) {
for (const auto& vertex : init) {
VertexType* vertices = static_cast<VertexType*>(addElement());
vertices[0] = std::get<0>(vertex);
Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/geometry/static_vertex_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <mbgl/geometry/buffer.hpp>

#include <array>
#include <vector>
#include <cstddef>
#include <cstdint>
Expand All @@ -26,7 +27,7 @@ class StaticRasterVertexBuffer : public Buffer<
> {
public:
using VertexType = int16_t;
StaticRasterVertexBuffer(std::initializer_list<std::tuple<VertexType, VertexType, VertexType, VertexType>>);
StaticRasterVertexBuffer(std::initializer_list<std::array<VertexType, 4>>);
};

} // namespace mbgl
11 changes: 9 additions & 2 deletions src/mbgl/renderer/painter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class Painter : private util::noncopyable {
std::unique_ptr<CircleShader> circleShader;

// Set up the stencil quad we're using to generate the stencil mask.
StaticVertexBuffer tileStencilBuffer = {
StaticVertexBuffer tileStencilBuffer {
// top left triangle
{ 0, 0 },
{ util::EXTENT, 0 },
Expand All @@ -224,13 +224,20 @@ class Painter : private util::noncopyable {
{ util::EXTENT, util::EXTENT },
};

StaticRasterVertexBuffer rasterBoundsBuffer {
{{ 0, 0, 0, 0 }},
{{ util::EXTENT, 0, 32767, 0 }},
{{ 0, util::EXTENT, 0, 32767 }},
{{ util::EXTENT, util::EXTENT, 32767, 32767 }},
};

VertexArrayObject coveringPlainArray;
VertexArrayObject coveringRasterArray;
VertexArrayObject backgroundPatternArray;
VertexArrayObject backgroundArray;

// Set up the tile boundary lines we're using to draw the tile outlines.
StaticVertexBuffer tileBorderBuffer = {
StaticVertexBuffer tileBorderBuffer {
{ 0, 0 },
{ util::EXTENT, 0 },
{ util::EXTENT, util::EXTENT },
Expand Down
16 changes: 11 additions & 5 deletions src/mbgl/renderer/painter_raster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ void Painter::renderRaster(RasterBucket& bucket,
if (bucket.hasData()) {
config.program = rasterShader->getID();
rasterShader->u_matrix = matrix;
rasterShader->u_buffer = 0;
rasterShader->u_opacity = properties.rasterOpacity;
rasterShader->u_buffer_scale = 1.0f;
rasterShader->u_opacity0 = properties.rasterOpacity;
rasterShader->u_opacity1 = 1.0f - properties.rasterOpacity;

rasterShader->u_brightness_low = properties.rasterBrightnessMin;
rasterShader->u_brightness_high = properties.rasterBrightnessMax;
rasterShader->u_saturation_factor = saturationFactor(properties.rasterSaturation);
Expand All @@ -30,14 +32,18 @@ void Painter::renderRaster(RasterBucket& bucket,

config.stencilTest = GL_FALSE;

rasterShader->u_image = 0;
config.activeTexture = GL_TEXTURE0;
rasterShader->u_image0 = 0; // GL_TEXTURE0
rasterShader->u_image1 = 1; // GL_TEXTURE1
rasterShader->u_tl_parent = {{ 0.0f, 0.0f }};
rasterShader->u_scale_parent = 1.0f;

config.depthFunc.reset();
config.depthTest = GL_TRUE;
config.depthMask = GL_FALSE;
setDepthSublayer(0);
bucket.drawRaster(*rasterShader, tileStencilBuffer, coveringRasterArray, store);

bucket.bindTextures(config, store);
bucket.drawRaster(*rasterShader, rasterBoundsBuffer, coveringRasterArray, store);
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/mbgl/renderer/raster_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ void RasterBucket::setImage(PremultipliedImage image) {
raster.load(std::move(image));
}

void RasterBucket::drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array, gl::ObjectStore& store) {
void RasterBucket::bindTextures(gl::Config& config, gl::ObjectStore& store) {
config.activeTexture = GL_TEXTURE0;
raster.bind(true, store);
config.activeTexture = GL_TEXTURE1;
raster.bind(true, store);
}

void RasterBucket::drawRaster(RasterShader& shader, StaticRasterVertexBuffer&vertices, VertexArrayObject &array, gl::ObjectStore& 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 {
Expand Down
4 changes: 3 additions & 1 deletion src/mbgl/renderer/raster_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <mbgl/renderer/bucket.hpp>
#include <mbgl/util/raster.hpp>
#include <mbgl/gl/gl_config.hpp>

namespace mbgl {

Expand All @@ -20,7 +21,8 @@ class RasterBucket : public Bucket {

void setImage(PremultipliedImage);

void drawRaster(RasterShader&, StaticVertexBuffer&, VertexArrayObject&, gl::ObjectStore&);
void bindTextures(gl::Config&, gl::ObjectStore&);
void drawRaster(RasterShader&, StaticRasterVertexBuffer&, VertexArrayObject&, gl::ObjectStore&);

Raster raster;
};
Expand Down
10 changes: 8 additions & 2 deletions src/mbgl/shader/raster_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
using namespace mbgl;

RasterShader::RasterShader(gl::ObjectStore& store)
: Shader("raster", shaders::raster::vertex, shaders::raster::fragment, store) {
: Shader("raster", shaders::raster::vertex, shaders::raster::fragment, store)
, a_texture_pos(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_texture_pos"))) {
}

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));
}
13 changes: 10 additions & 3 deletions src/mbgl/shader/raster_shader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ class RasterShader : public Shader {
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};

protected:
GLint a_texture_pos = -1;
};

} // namespace mbgl

0 comments on commit 272da62

Please sign in to comment.