[gl] Use Shader::getID() whenever possible

This commit is contained in:
Bruno de Oliveira Abinader
2016-02-14 13:17:59 +02:00
parent ee72e93f94
commit 0386dc7a4e
15 changed files with 32 additions and 30 deletions

View File

@@ -270,7 +270,7 @@ void Painter::renderBackground(const BackgroundLayer& layer) {
float zoomFraction = state.getZoomFraction();
config.program = patternShader->program;
config.program = patternShader->getID();
patternShader->u_matrix = identityMatrix;
patternShader->u_pattern_tl_a = (*imagePosA).tl;
patternShader->u_pattern_br_a = (*imagePosA).br;
@@ -325,7 +325,7 @@ void Painter::renderBackground(const BackgroundLayer& layer) {
color[2] *= properties.opacity;
color[3] *= properties.opacity;
config.program = plainShader->program;
config.program = plainShader->getID();
plainShader->u_matrix = identityMatrix;
plainShader->u_color = color;
backgroundArray.bind(*plainShader, backgroundBuffer, BUFFER_OFFSET(0));

View File

@@ -38,7 +38,7 @@ void Painter::renderCircle(CircleBucket& bucket,
// are inversely related.
float antialiasing = 1 / data.pixelRatio / properties.radius;
config.program = circleShader->program;
config.program = circleShader->getID();
circleShader->u_matrix = vtxMatrix;
circleShader->u_exmatrix = extrudeMatrix;

View File

@@ -13,7 +13,7 @@ void Painter::drawClippingMasks(const std::map<TileID, ClipID>& stencils) {
mat4 matrix;
const GLuint mask = 0b11111111;
config.program = plainShader->program;
config.program = plainShader->getID();
config.stencilOp.reset();
config.stencilTest = GL_TRUE;
config.depthTest = GL_FALSE;

View File

@@ -33,7 +33,7 @@ void Painter::renderDebugText(TileData& tileData, const mat4 &matrix) {
tileData.debugBucket = std::make_unique<DebugBucket>(tileData.id, tileData.getState(), tileData.modified, tileData.expires, data.getDebug());
}
config.program = plainShader->program;
config.program = plainShader->getID();
plainShader->u_matrix = matrix;
// Draw white outline
@@ -66,7 +66,7 @@ void Painter::renderDebugFrame(const mat4 &matrix) {
config.stencilOp.reset();
config.stencilTest = GL_TRUE;
config.program = plainShader->program;
config.program = plainShader->getID();
plainShader->u_matrix = matrix;
// draw tile outline

View File

@@ -44,7 +44,7 @@ void Painter::renderFill(FillBucket& bucket, const FillLayer& layer, const TileI
// Because we're drawing top-to-bottom, and we update the stencil mask
// befrom, we have to draw the outline first (!)
if (outline && pass == RenderPass::Translucent) {
config.program = outlineShader->program;
config.program = outlineShader->getID();
outlineShader->u_matrix = vtxMatrix;
config.lineWidth = 2.0f; // This is always fixed and does not depend on the pixelRatio!
@@ -78,7 +78,7 @@ void Painter::renderFill(FillBucket& bucket, const FillLayer& layer, const TileI
1.0f / ((*posB).size[0] * factor * properties.pattern.value.toScale),
1.0f / ((*posB).size[1] * factor * properties.pattern.value.toScale));
config.program = patternShader->program;
config.program = patternShader->getID();
patternShader->u_matrix = vtxMatrix;
patternShader->u_pattern_tl_a = (*posA).tl;
patternShader->u_pattern_br_a = (*posA).br;
@@ -125,7 +125,7 @@ void Painter::renderFill(FillBucket& bucket, const FillLayer& layer, const TileI
// fragments or when it's translucent and we're drawing translucent
// fragments
// Draw filling rectangle.
config.program = plainShader->program;
config.program = plainShader->getID();
plainShader->u_matrix = vtxMatrix;
plainShader->u_color = fill_color;
@@ -138,7 +138,7 @@ void Painter::renderFill(FillBucket& bucket, const FillLayer& layer, const TileI
// Because we're drawing top-to-bottom, and we update the stencil mask
// below, we have to draw the outline first (!)
if (fringeline && pass == RenderPass::Translucent) {
config.program = outlineShader->program;
config.program = outlineShader->getID();
outlineShader->u_matrix = vtxMatrix;
config.lineWidth = 2.0f; // This is always fixed and does not depend on the pixelRatio!

View File

@@ -70,7 +70,7 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI
if (!properties.dasharray.value.from.empty()) {
config.program = linesdfShader->program;
config.program = linesdfShader->getID();
linesdfShader->u_matrix = vtxMatrix;
linesdfShader->u_exmatrix = extrudeMatrix;
@@ -113,7 +113,7 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI
float factor = util::EXTENT / (512 * id.overscaling) / std::pow(2, state.getIntegerZoom() - id.z);
config.program = linepatternShader->program;
config.program = linepatternShader->getID();
linepatternShader->u_matrix = vtxMatrix;
linepatternShader->u_exmatrix = extrudeMatrix;
@@ -139,7 +139,7 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI
bucket.drawLinePatterns(*linepatternShader);
} else {
config.program = lineShader->program;
config.program = lineShader->getID();
lineShader->u_matrix = vtxMatrix;
lineShader->u_exmatrix = extrudeMatrix;

View File

@@ -12,7 +12,7 @@ void Painter::renderRaster(RasterBucket& bucket, const RasterLayer& layer, const
const RasterPaintProperties& properties = layer.paint;
if (bucket.hasData()) {
config.program = rasterShader->program;
config.program = rasterShader->getID();
rasterShader->u_matrix = matrix;
rasterShader->u_buffer = 0;
rasterShader->u_opacity = properties.opacity;

View File

@@ -49,7 +49,7 @@ void Painter::renderSDF(SymbolBucket &bucket,
float fontScale = fontSize / sdfFontSize;
matrix::scale(exMatrix, exMatrix, fontScale, fontScale, 1.0f);
config.program = sdfShader.program;
config.program = sdfShader.getID();
sdfShader.u_matrix = vtxMatrix;
sdfShader.u_exmatrix = exMatrix;
sdfShader.u_texsize = texsize;
@@ -211,7 +211,7 @@ void Painter::renderSymbol(SymbolBucket& bucket, const SymbolLayer& layer, const
float x = state.getHeight() / 2.0f * std::tan(state.getPitch());
float extra = (topedgelength + x) / topedgelength - 1;
config.program = iconShader->program;
config.program = iconShader->getID();
iconShader->u_matrix = vtxMatrix;
iconShader->u_exmatrix = exMatrix;
iconShader->u_texsize = {{ float(activeSpriteAtlas->getWidth()) / 4.0f, float(activeSpriteAtlas->getHeight()) / 4.0f }};
@@ -259,7 +259,7 @@ void Painter::renderSymbol(SymbolBucket& bucket, const SymbolLayer& layer, const
config.stencilOp.reset();
config.stencilTest = GL_TRUE;
config.program = collisionBoxShader->program;
config.program = collisionBoxShader->getID();
collisionBoxShader->u_matrix = matrix;
collisionBoxShader->u_scale = std::pow(2, state.getZoom() - id.z);
collisionBoxShader->u_zoom = state.getZoom() * 10;

View File

@@ -9,8 +9,8 @@ using namespace mbgl;
CollisionBoxShader::CollisionBoxShader()
: Shader("collisionbox", shaders::box::vertex, shaders::box::fragment) {
a_extrude = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_extrude"));
a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data"));
a_extrude = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_extrude"));
a_data = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data"));
}
void CollisionBoxShader::bind(GLbyte *offset) {

View File

@@ -8,9 +8,9 @@
using namespace mbgl;
IconShader::IconShader() : Shader("icon", shaders::icon::vertex, shaders::icon::fragment) {
a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_offset"));
a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data1"));
a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data2"));
a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_offset"));
a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data1"));
a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data2"));
}
void IconShader::bind(GLbyte* offset) {

View File

@@ -8,7 +8,7 @@
using namespace mbgl;
LineShader::LineShader() : Shader("line", shaders::line::vertex, shaders::line::fragment) {
a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data"));
a_data = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data"));
}
void LineShader::bind(GLbyte* offset) {

View File

@@ -9,7 +9,7 @@ using namespace mbgl;
LinepatternShader::LinepatternShader()
: Shader("linepattern", shaders::linepattern::vertex, shaders::linepattern::fragment) {
a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data"));
a_data = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data"));
}
void LinepatternShader::bind(GLbyte* offset) {

View File

@@ -9,7 +9,7 @@ using namespace mbgl;
LineSDFShader::LineSDFShader()
: Shader("line", shaders::linesdf::vertex, shaders::linesdf::fragment) {
a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data"));
a_data = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data"));
}
void LineSDFShader::bind(GLbyte* offset) {

View File

@@ -8,9 +8,9 @@
using namespace mbgl;
SDFShader::SDFShader() : Shader("sdf", shaders::sdf::vertex, shaders::sdf::fragment) {
a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_offset"));
a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data1"));
a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data2"));
a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_offset"));
a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data1"));
a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data2"));
}
void SDFGlyphShader::bind(GLbyte* offset) {

View File

@@ -4,13 +4,15 @@
#include <mbgl/shader/shader.hpp>
#include <mbgl/gl/gl.hpp>
#include <array>
namespace mbgl {
template <typename T>
class Uniform {
public:
Uniform(const GLchar* name, const Shader& shader) : current() {
location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.program, name));
location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.getID(), name));
}
void operator=(const T& t) {
@@ -33,7 +35,7 @@ public:
typedef std::array<float, C*R> T;
UniformMatrix(const GLchar* name, const Shader& shader) : current() {
location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.program, name));
location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.getID(), name));
}
void operator=(const std::array<double, C*R>& t) {